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

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

Issue 11308124: Hide new Autofill Popup on Main Widget Resize or Move. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "autofill_popup_view_views.h" 5 #include "autofill_popup_view_views.h"
6 6
7 #include "chrome/browser/ui/views/autofill/autofill_external_delegate_views.h" 7 #include "chrome/browser/ui/views/autofill/autofill_external_delegate_views.h"
8 #include "content/public/browser/render_view_host.h" 8 #include "content/public/browser/render_view_host.h"
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 #include "content/public/browser/web_contents_view.h" 10 #include "content/public/browser/web_contents_view.h"
(...skipping 27 matching lines...) Expand all
38 } 38 }
39 39
40 AutofillPopupViewViews::~AutofillPopupViewViews() { 40 AutofillPopupViewViews::~AutofillPopupViewViews() {
41 external_delegate_->InvalidateView(); 41 external_delegate_->InvalidateView();
42 } 42 }
43 43
44 void AutofillPopupViewViews::Hide() { 44 void AutofillPopupViewViews::Hide() {
45 if (GetWidget()) 45 if (GetWidget())
46 GetWidget()->Close(); 46 GetWidget()->Close();
47 web_contents_->GetRenderViewHost()->RemoveKeyboardListener(this); 47 web_contents_->GetRenderViewHost()->RemoveKeyboardListener(this);
48
49 views::Widget* browser_widget =
50 views::Widget::GetTopLevelWidgetForNativeView(
51 web_contents_->GetView()->GetTopLevelNativeWindow());
52 browser_widget->RemoveObserver(this);
48 } 53 }
49 54
50 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { 55 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) {
51 canvas->DrawColor(kPopupBackground); 56 canvas->DrawColor(kPopupBackground);
52 OnPaintBorder(canvas); 57 OnPaintBorder(canvas);
53 58
54 for (size_t i = 0; i < autofill_values().size(); ++i) { 59 for (size_t i = 0; i < autofill_values().size(); ++i) {
55 gfx::Rect line_rect = GetRectForRow(i, width()); 60 gfx::Rect line_rect = GetRectForRow(i, width());
56 61
57 if (autofill_unique_ids()[i] == WebAutofillClient::MenuItemIDSeparator) 62 if (autofill_unique_ids()[i] == WebAutofillClient::MenuItemIDSeparator)
58 canvas->DrawRect(line_rect, kLabelTextColor); 63 canvas->DrawRect(line_rect, kLabelTextColor);
59 else 64 else
60 DrawAutofillEntry(canvas, i, line_rect); 65 DrawAutofillEntry(canvas, i, line_rect);
61 } 66 }
62 } 67 }
63 68
69 void AutofillPopupViewViews::OnWidgetMoved(views::Widget* widget) {
70 external_delegate()->HideAutofillPopup();
71 }
72
73 void AutofillPopupViewViews::OnWidgetSizeChanged(views::Widget* widget,
74 const gfx::Size& size) {
75 external_delegate()->HideAutofillPopup();
76 }
77
64 bool AutofillPopupViewViews::HandleKeyPressEvent(ui::KeyEvent* event) { 78 bool AutofillPopupViewViews::HandleKeyPressEvent(ui::KeyEvent* event) {
65 switch (event->key_code()) { 79 switch (event->key_code()) {
66 case ui::VKEY_UP: 80 case ui::VKEY_UP:
67 SelectPreviousLine(); 81 SelectPreviousLine();
68 return true; 82 return true;
69 case ui::VKEY_DOWN: 83 case ui::VKEY_DOWN:
70 SelectNextLine(); 84 SelectNextLine();
71 return true; 85 return true;
72 case ui::VKEY_PRIOR: 86 case ui::VKEY_PRIOR:
73 SetSelectedLine(0); 87 SetSelectedLine(0);
74 return true; 88 return true;
75 case ui::VKEY_NEXT: 89 case ui::VKEY_NEXT:
76 SetSelectedLine(autofill_values().size() - 1); 90 SetSelectedLine(autofill_values().size() - 1);
77 return true; 91 return true;
78 case ui::VKEY_ESCAPE: 92 case ui::VKEY_ESCAPE:
79 if (external_delegate()) { 93 external_delegate()->HideAutofillPopup();
80 external_delegate()->HideAutofillPopup();
81 } else {
82 Hide();
83 }
84 return true; 94 return true;
85 case ui::VKEY_DELETE: 95 case ui::VKEY_DELETE:
86 return event->IsShiftDown() && RemoveSelectedLine(); 96 return event->IsShiftDown() && RemoveSelectedLine();
87 case ui::VKEY_RETURN: 97 case ui::VKEY_RETURN:
88 return AcceptSelectedLine(); 98 return AcceptSelectedLine();
89 default: 99 default:
90 return false; 100 return false;
91 } 101 }
92 } 102 }
93 103
94 void AutofillPopupViewViews::ShowInternal() { 104 void AutofillPopupViewViews::ShowInternal() {
95 if (!GetWidget()) { 105 if (!GetWidget()) {
96 // The widget is destroyed by the corresponding NativeWidget, so we use 106 // The widget is destroyed by the corresponding NativeWidget, so we use
97 // a weak pointer to hold the reference and don't have to worry about 107 // a weak pointer to hold the reference and don't have to worry about
98 // deletion. 108 // deletion.
99 views::Widget* widget = new views::Widget; 109 views::Widget* widget = new views::Widget;
100 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 110 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
101 params.delegate = this; 111 params.delegate = this;
102 params.can_activate = false; 112 params.can_activate = false;
103 params.transparent = true; 113 params.transparent = true;
104 params.parent = web_contents_->GetView()->GetTopLevelNativeWindow(); 114 params.parent = web_contents_->GetView()->GetTopLevelNativeWindow();
105 widget->Init(params); 115 widget->Init(params);
106 widget->SetContentsView(this); 116 widget->SetContentsView(this);
107 widget->Show(); 117 widget->Show();
108 118
109 gfx::Rect client_area; 119 gfx::Rect client_area;
110 web_contents_->GetContainerBounds(&client_area); 120 web_contents_->GetContainerBounds(&client_area);
111 widget->SetBounds(client_area); 121 widget->SetBounds(client_area);
122
123 // Setup an observer to check for when the browser moves or changes size,
124 // since the popup should always be hidden in those cases.
125 views::Widget* browser_widget =
126 views::Widget::GetTopLevelWidgetForNativeView(
127 web_contents_->GetView()->GetTopLevelNativeWindow());
128 browser_widget->AddObserver(this);
112 } 129 }
113 130
114 set_border(views::Border::CreateSolidBorder(kBorderThickness, kBorderColor)); 131 set_border(views::Border::CreateSolidBorder(kBorderThickness, kBorderColor));
115 132
116 UpdateBoundsAndRedrawPopup(); 133 UpdateBoundsAndRedrawPopup();
117 134
118 web_contents_->GetRenderViewHost()->AddKeyboardListener(this); 135 web_contents_->GetRenderViewHost()->AddKeyboardListener(this);
119 } 136 }
120 137
121 void AutofillPopupViewViews::InvalidateRow(size_t row) { 138 void AutofillPopupViewViews::InvalidateRow(size_t row) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 canvas->DrawStringInt( 201 canvas->DrawStringInt(
185 autofill_labels()[index], 202 autofill_labels()[index],
186 label_font(), 203 label_font(),
187 kLabelTextColor, 204 kLabelTextColor,
188 x_align_left + kEndPadding, 205 x_align_left + kEndPadding,
189 entry_rect.y(), 206 entry_rect.y(),
190 canvas->GetStringWidth(autofill_labels()[index], label_font()), 207 canvas->GetStringWidth(autofill_labels()[index], label_font()),
191 entry_rect.height(), 208 entry_rect.height(),
192 gfx::Canvas::TEXT_ALIGN_CENTER); 209 gfx::Canvas::TEXT_ALIGN_CENTER);
193 } 210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698