15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/views/autofill/autofill_popup_base_view.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "base/bind.h" 8effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "base/location.h" 9effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "base/message_loop/message_loop.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/autofill/popup_constants.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/border.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/widget/widget.h" 13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/window_animations.h" 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace autofill { 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const SkColor AutofillPopupBaseView::kBorderColor = 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SkColorSetARGB(0xFF, 0xC7, 0xCA, 0xCE); 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const SkColor AutofillPopupBaseView::kHoveredBackgroundColor = 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SkColorSetARGB(0xFF, 0xCD, 0xCD, 0xCD); 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const SkColor AutofillPopupBaseView::kItemTextColor = 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SkColorSetARGB(0xFF, 0x7F, 0x7F, 0x7F); 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const SkColor AutofillPopupBaseView::kPopupBackground = 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF); 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const SkColor AutofillPopupBaseView::kValueTextColor = 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SkColorSetARGB(0xFF, 0x00, 0x00, 0x00); 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const SkColor AutofillPopupBaseView::kWarningTextColor = 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SkColorSetARGB(0xFF, 0x7F, 0x7F, 0x7F); 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)AutofillPopupBaseView::AutofillPopupBaseView( 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AutofillPopupViewDelegate* delegate, 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) views::Widget* observing_widget) 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : delegate_(delegate), 34effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch observing_widget_(observing_widget), 35effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch weak_ptr_factory_(this) {} 36effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)AutofillPopupBaseView::~AutofillPopupBaseView() { 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (delegate_) { 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delegate_->ViewDestroyed(); 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RemoveObserver(); 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::DoShow() { 46010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const bool initialize_widget = !GetWidget(); 47010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (initialize_widget) { 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) observing_widget_->AddObserver(this); 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 50effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch views::FocusManager* focus_manager = observing_widget_->GetFocusManager(); 51effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch focus_manager->RegisterAccelerator( 52effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE), 53effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::AcceleratorManager::kNormalPriority, 54effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch this); 55effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch focus_manager->RegisterAccelerator( 56effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE), 57effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch ui::AcceleratorManager::kNormalPriority, 58effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch this); 59effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The widget is destroyed by the corresponding NativeWidget, so we use 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // a weak pointer to hold the reference and don't have to worry about 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // deletion. 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) views::Widget* widget = new views::Widget; 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.delegate = this; 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.parent = container_view(); 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) widget->Init(params); 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) widget->SetContentsView(this); 695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // No animation for popup appearance (too distracting). 71a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) wm::SetWindowVisibilityAnimationTransition( 72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) widget->GetNativeView(), wm::ANIMATE_HIDE); 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetBorder(views::Border::CreateSolidBorder(kPopupBorderThickness, 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) kBorderColor)); 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DoUpdateBoundsAndRedrawPopup(); 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetWidget()->Show(); 80010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 81010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Showing the widget can change native focus (which would result in an 82010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // immediate hiding of the popup). Only start observing after shown. 83010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (initialize_widget) 84010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this); 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::DoHide() { 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The controller is no longer valid after it hides us. 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delegate_ = NULL; 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RemoveObserver(); 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (GetWidget()) { 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Don't call CloseNow() because some of the functions higher up the stack 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // assume the the widget is still valid after this point. 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // http://crbug.com/229224 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // NOTE: This deletes |this|. 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetWidget()->Close(); 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delete this; 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::RemoveObserver() { 105effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch observing_widget_->GetFocusManager()->UnregisterAccelerators(this); 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) observing_widget_->RemoveObserver(this); 107c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); 1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::DoUpdateBoundsAndRedrawPopup() { 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetWidget()->SetBounds(delegate_->popup_bounds()); 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SchedulePaint(); 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 115c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid AutofillPopupBaseView::OnNativeFocusChange( 116c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch gfx::NativeView focused_before, 117c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch gfx::NativeView focused_now) { 118c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch if (GetWidget() && GetWidget()->GetNativeView() != focused_now) 119c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch HideController(); 120c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch} 121c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::OnWidgetBoundsChanged(views::Widget* widget, 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Rect& new_bounds) { 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK_EQ(widget, observing_widget_); 1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) HideController(); 1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::OnMouseCaptureLost() { 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ClearSelection(); 1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool AutofillPopupBaseView::OnMouseDragged(const ui::MouseEvent& event) { 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (HitTestPoint(event.location())) { 1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetSelection(event.location()); 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We must return true in order to get future OnMouseDragged and 1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // OnMouseReleased events. 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If we move off of the popup, we lose the selection. 1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ClearSelection(); 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::OnMouseExited(const ui::MouseEvent& event) { 147effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Pressing return causes the cursor to hide, which will generate an 148effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // OnMouseExited event. Pressing return should activate the current selection 149effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // via AcceleratorPressed, so we need to let that run first. 150effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch base::MessageLoop::current()->PostTask( 151effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch FROM_HERE, 152effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch base::Bind(&AutofillPopupBaseView::ClearSelection, 153effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch weak_ptr_factory_.GetWeakPtr())); 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::OnMouseMoved(const ui::MouseEvent& event) { 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (HitTestPoint(event.location())) 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetSelection(event.location()); 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) else 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ClearSelection(); 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool AutofillPopupBaseView::OnMousePressed(const ui::MouseEvent& event) { 16446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) return event.GetClickCount() == 1; 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::OnMouseReleased(const ui::MouseEvent& event) { 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We only care about the left click. 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AcceptSelection(event.location()); 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::OnGestureEvent(ui::GestureEvent* event) { 1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) switch (event->type()) { 1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::ET_GESTURE_TAP_DOWN: 1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::ET_GESTURE_SCROLL_BEGIN: 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::ET_GESTURE_SCROLL_UPDATE: 1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (HitTestPoint(event->location())) 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetSelection(event->location()); 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) else 1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ClearSelection(); 1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) break; 1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::ET_GESTURE_TAP: 1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::ET_GESTURE_SCROLL_END: 1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (HitTestPoint(event->location())) 186a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AcceptSelection(event->location()); 1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) else 1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ClearSelection(); 1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) break; 1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::ET_GESTURE_TAP_CANCEL: 1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) case ui::ET_SCROLL_FLING_START: 1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ClearSelection(); 1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) break; 1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) default: 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event->SetHandled(); 1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 200effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochbool AutofillPopupBaseView::AcceleratorPressed( 201effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const ui::Accelerator& accelerator) { 202effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch DCHECK_EQ(accelerator.modifiers(), ui::EF_NONE); 203effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 204effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (accelerator.key_code() == ui::VKEY_ESCAPE) { 205effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch HideController(); 206effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return true; 207effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 208effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 209effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (accelerator.key_code() == ui::VKEY_RETURN) 210effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return delegate_->AcceptSelectedLine(); 211effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 212effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch NOTREACHED(); 213effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return false; 214effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 215effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::SetSelection(const gfx::Point& point) { 2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (delegate_) 2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delegate_->SetSelectionAtPoint(point); 2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::AcceptSelection(const gfx::Point& point) { 222effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!delegate_) 223effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 224effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 225effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch delegate_->SetSelectionAtPoint(point); 226effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch delegate_->AcceptSelectedLine(); 2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::ClearSelection() { 2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (delegate_) 2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delegate_->SelectionCleared(); 2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AutofillPopupBaseView::HideController() { 2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (delegate_) 2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delegate_->Hide(); 2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::NativeView AutofillPopupBaseView::container_view() { 2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return delegate_->container_view(); 2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace autofill 244