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

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: Merging to OnWidgetBoundsChanged 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::OnWidgetBoundsChanged(views::Widget* widget,
70 const gfx::Rect& new_bounds) {
71 external_delegate()->HideAutofillPopup();
72 }
73
64 bool AutofillPopupViewViews::HandleKeyPressEvent(ui::KeyEvent* event) { 74 bool AutofillPopupViewViews::HandleKeyPressEvent(ui::KeyEvent* event) {
65 switch (event->key_code()) { 75 switch (event->key_code()) {
66 case ui::VKEY_UP: 76 case ui::VKEY_UP:
67 SelectPreviousLine(); 77 SelectPreviousLine();
68 return true; 78 return true;
69 case ui::VKEY_DOWN: 79 case ui::VKEY_DOWN:
70 SelectNextLine(); 80 SelectNextLine();
71 return true; 81 return true;
72 case ui::VKEY_PRIOR: 82 case ui::VKEY_PRIOR:
73 SetSelectedLine(0); 83 SetSelectedLine(0);
74 return true; 84 return true;
75 case ui::VKEY_NEXT: 85 case ui::VKEY_NEXT:
76 SetSelectedLine(autofill_values().size() - 1); 86 SetSelectedLine(autofill_values().size() - 1);
77 return true; 87 return true;
78 case ui::VKEY_ESCAPE: 88 case ui::VKEY_ESCAPE:
79 if (external_delegate()) { 89 external_delegate()->HideAutofillPopup();
80 external_delegate()->HideAutofillPopup();
81 } else {
82 Hide();
83 }
84 return true; 90 return true;
85 case ui::VKEY_DELETE: 91 case ui::VKEY_DELETE:
86 return event->IsShiftDown() && RemoveSelectedLine(); 92 return event->IsShiftDown() && RemoveSelectedLine();
87 case ui::VKEY_RETURN: 93 case ui::VKEY_RETURN:
88 return AcceptSelectedLine(); 94 return AcceptSelectedLine();
89 default: 95 default:
90 return false; 96 return false;
91 } 97 }
92 } 98 }
93 99
94 void AutofillPopupViewViews::ShowInternal() { 100 void AutofillPopupViewViews::ShowInternal() {
95 if (!GetWidget()) { 101 if (!GetWidget()) {
96 // The widget is destroyed by the corresponding NativeWidget, so we use 102 // 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 103 // a weak pointer to hold the reference and don't have to worry about
98 // deletion. 104 // deletion.
99 views::Widget* widget = new views::Widget; 105 views::Widget* widget = new views::Widget;
100 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 106 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
101 params.delegate = this; 107 params.delegate = this;
102 params.can_activate = false; 108 params.can_activate = false;
103 params.transparent = true; 109 params.transparent = true;
104 params.parent = web_contents_->GetView()->GetTopLevelNativeWindow(); 110 params.parent = web_contents_->GetView()->GetTopLevelNativeWindow();
105 widget->Init(params); 111 widget->Init(params);
106 widget->SetContentsView(this); 112 widget->SetContentsView(this);
107 widget->Show(); 113 widget->Show();
108 114
109 gfx::Rect client_area; 115 gfx::Rect client_area;
110 web_contents_->GetContainerBounds(&client_area); 116 web_contents_->GetContainerBounds(&client_area);
111 widget->SetBounds(client_area); 117 widget->SetBounds(client_area);
118
119 // Setup an observer to check for when the browser moves or changes size,
120 // since the popup should always be hidden in those cases.
121 views::Widget* browser_widget =
122 views::Widget::GetTopLevelWidgetForNativeView(
123 web_contents_->GetView()->GetTopLevelNativeWindow());
124 browser_widget->AddObserver(this);
112 } 125 }
113 126
114 set_border(views::Border::CreateSolidBorder(kBorderThickness, kBorderColor)); 127 set_border(views::Border::CreateSolidBorder(kBorderThickness, kBorderColor));
115 128
116 UpdateBoundsAndRedrawPopup(); 129 UpdateBoundsAndRedrawPopup();
117 130
118 web_contents_->GetRenderViewHost()->AddKeyboardListener(this); 131 web_contents_->GetRenderViewHost()->AddKeyboardListener(this);
119 } 132 }
120 133
121 void AutofillPopupViewViews::InvalidateRow(size_t row) { 134 void AutofillPopupViewViews::InvalidateRow(size_t row) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 canvas->DrawStringInt( 197 canvas->DrawStringInt(
185 autofill_labels()[index], 198 autofill_labels()[index],
186 label_font(), 199 label_font(),
187 kLabelTextColor, 200 kLabelTextColor,
188 x_align_left + kEndPadding, 201 x_align_left + kEndPadding,
189 entry_rect.y(), 202 entry_rect.y(),
190 canvas->GetStringWidth(autofill_labels()[index], label_font()), 203 canvas->GetStringWidth(autofill_labels()[index], label_font()),
191 entry_rect.height(), 204 entry_rect.height(),
192 gfx::Canvas::TEXT_ALIGN_CENTER); 205 gfx::Canvas::TEXT_ALIGN_CENTER);
193 } 206 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_popup_view_views.h ('k') | chrome/browser/ui/views/tabs/tab_drag_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698