Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: chrome/browser/ui/views/autofill/autofill_popup_base_view.cc

Issue 870833002: [android] Autofill popup behavior fixes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove redundant hide-on-resize on Views. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/autofill/autofill_popup_base_view.h" 5 #include "chrome/browser/ui/views/autofill/autofill_popup_base_view.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/ui/autofill/popup_constants.h" 10 #include "chrome/browser/ui/autofill/popup_constants.h"
11 #include "ui/views/border.h" 11 #include "ui/views/border.h"
12 #include "ui/views/focus/focus_manager.h"
12 #include "ui/views/widget/widget.h" 13 #include "ui/views/widget/widget.h"
13 14
14 namespace autofill { 15 namespace autofill {
15 16
16 const SkColor AutofillPopupBaseView::kBorderColor = 17 const SkColor AutofillPopupBaseView::kBorderColor =
17 SkColorSetARGB(0xFF, 0xC7, 0xCA, 0xCE); 18 SkColorSetARGB(0xFF, 0xC7, 0xCA, 0xCE);
18 const SkColor AutofillPopupBaseView::kHoveredBackgroundColor = 19 const SkColor AutofillPopupBaseView::kHoveredBackgroundColor =
19 SkColorSetARGB(0xFF, 0xCD, 0xCD, 0xCD); 20 SkColorSetARGB(0xFF, 0xCD, 0xCD, 0xCD);
20 const SkColor AutofillPopupBaseView::kItemTextColor = 21 const SkColor AutofillPopupBaseView::kItemTextColor =
21 SkColorSetARGB(0xFF, 0x7F, 0x7F, 0x7F); 22 SkColorSetARGB(0xFF, 0x7F, 0x7F, 0x7F);
22 const SkColor AutofillPopupBaseView::kPopupBackground = 23 const SkColor AutofillPopupBaseView::kPopupBackground =
23 SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF); 24 SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF);
24 const SkColor AutofillPopupBaseView::kValueTextColor = 25 const SkColor AutofillPopupBaseView::kValueTextColor =
25 SkColorSetARGB(0xFF, 0x00, 0x00, 0x00); 26 SkColorSetARGB(0xFF, 0x00, 0x00, 0x00);
26 const SkColor AutofillPopupBaseView::kWarningTextColor = 27 const SkColor AutofillPopupBaseView::kWarningTextColor =
27 SkColorSetARGB(0xFF, 0x7F, 0x7F, 0x7F); 28 SkColorSetARGB(0xFF, 0x7F, 0x7F, 0x7F);
28 29
29 AutofillPopupBaseView::AutofillPopupBaseView( 30 AutofillPopupBaseView::AutofillPopupBaseView(
30 AutofillPopupViewDelegate* delegate, 31 AutofillPopupViewDelegate* delegate,
31 views::Widget* observing_widget) 32 views::FocusManager* focus_manager)
32 : delegate_(delegate), 33 : delegate_(delegate),
33 observing_widget_(observing_widget), 34 focus_manager_(focus_manager),
34 weak_ptr_factory_(this) {} 35 weak_ptr_factory_(this) {}
35 36
36 AutofillPopupBaseView::~AutofillPopupBaseView() { 37 AutofillPopupBaseView::~AutofillPopupBaseView() {
37 if (delegate_) { 38 if (delegate_) {
38 delegate_->ViewDestroyed(); 39 delegate_->ViewDestroyed();
39 40
40 RemoveObserver(); 41 RemoveObserver();
41 } 42 }
42 } 43 }
43 44
44 void AutofillPopupBaseView::DoShow() { 45 void AutofillPopupBaseView::DoShow() {
45 const bool initialize_widget = !GetWidget(); 46 const bool initialize_widget = !GetWidget();
46 if (initialize_widget) { 47 if (initialize_widget) {
47 observing_widget_->AddObserver(this); 48 focus_manager_->RegisterAccelerator(
48
49 views::FocusManager* focus_manager = observing_widget_->GetFocusManager();
50 focus_manager->RegisterAccelerator(
51 ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE), 49 ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE),
52 ui::AcceleratorManager::kNormalPriority, 50 ui::AcceleratorManager::kNormalPriority,
53 this); 51 this);
54 focus_manager->RegisterAccelerator( 52 focus_manager_->RegisterAccelerator(
55 ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE), 53 ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE),
56 ui::AcceleratorManager::kNormalPriority, 54 ui::AcceleratorManager::kNormalPriority,
57 this); 55 this);
58 56
59 // The widget is destroyed by the corresponding NativeWidget, so we use 57 // The widget is destroyed by the corresponding NativeWidget, so we use
60 // a weak pointer to hold the reference and don't have to worry about 58 // a weak pointer to hold the reference and don't have to worry about
61 // deletion. 59 // deletion.
62 views::Widget* widget = new views::Widget; 60 views::Widget* widget = new views::Widget;
63 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 61 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
64 params.delegate = this; 62 params.delegate = this;
(...skipping 28 matching lines...) Expand all
93 // assume the the widget is still valid after this point. 91 // assume the the widget is still valid after this point.
94 // http://crbug.com/229224 92 // http://crbug.com/229224
95 // NOTE: This deletes |this|. 93 // NOTE: This deletes |this|.
96 GetWidget()->Close(); 94 GetWidget()->Close();
97 } else { 95 } else {
98 delete this; 96 delete this;
99 } 97 }
100 } 98 }
101 99
102 void AutofillPopupBaseView::RemoveObserver() { 100 void AutofillPopupBaseView::RemoveObserver() {
103 observing_widget_->GetFocusManager()->UnregisterAccelerators(this); 101 focus_manager_->UnregisterAccelerators(this);
Evan Stade 2015/01/26 20:21:54 Seems like this could cause problems during shutdo
sky 2015/01/26 22:26:53 Is focus_manager_ from another widget? If so, I ag
please use gerrit instead 2015/01/26 23:49:03 An instance of FocusManager is created when initia
Evan Stade 2015/01/27 00:01:43 do you even need to pass the focus manager? You ca
please use gerrit instead 2015/01/27 20:02:41 I've tried using the focus manager of the widget c
104 observing_widget_->RemoveObserver(this);
105 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); 102 views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this);
106 } 103 }
107 104
108 void AutofillPopupBaseView::DoUpdateBoundsAndRedrawPopup() { 105 void AutofillPopupBaseView::DoUpdateBoundsAndRedrawPopup() {
109 GetWidget()->SetBounds(delegate_->popup_bounds()); 106 GetWidget()->SetBounds(delegate_->popup_bounds());
110 SchedulePaint(); 107 SchedulePaint();
111 } 108 }
112 109
113 void AutofillPopupBaseView::OnNativeFocusChange( 110 void AutofillPopupBaseView::OnNativeFocusChange(
114 gfx::NativeView focused_before, 111 gfx::NativeView focused_before,
115 gfx::NativeView focused_now) { 112 gfx::NativeView focused_now) {
116 if (GetWidget() && GetWidget()->GetNativeView() != focused_now) 113 if (GetWidget() && GetWidget()->GetNativeView() != focused_now)
117 HideController(); 114 HideController();
118 } 115 }
119 116
120 void AutofillPopupBaseView::OnWidgetBoundsChanged(views::Widget* widget,
121 const gfx::Rect& new_bounds) {
122 DCHECK_EQ(widget, observing_widget_);
123 HideController();
124 }
125
126 void AutofillPopupBaseView::OnMouseCaptureLost() { 117 void AutofillPopupBaseView::OnMouseCaptureLost() {
127 ClearSelection(); 118 ClearSelection();
128 } 119 }
129 120
130 bool AutofillPopupBaseView::OnMouseDragged(const ui::MouseEvent& event) { 121 bool AutofillPopupBaseView::OnMouseDragged(const ui::MouseEvent& event) {
131 if (HitTestPoint(event.location())) { 122 if (HitTestPoint(event.location())) {
132 SetSelection(event.location()); 123 SetSelection(event.location());
133 124
134 // We must return true in order to get future OnMouseDragged and 125 // We must return true in order to get future OnMouseDragged and
135 // OnMouseReleased events. 126 // OnMouseReleased events.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 void AutofillPopupBaseView::HideController() { 223 void AutofillPopupBaseView::HideController() {
233 if (delegate_) 224 if (delegate_)
234 delegate_->Hide(); 225 delegate_->Hide();
235 } 226 }
236 227
237 gfx::NativeView AutofillPopupBaseView::container_view() { 228 gfx::NativeView AutofillPopupBaseView::container_view() {
238 return delegate_->container_view(); 229 return delegate_->container_view();
239 } 230 }
240 231
241 } // namespace autofill 232 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698