OLD | NEW |
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 "chrome/browser/ui/views/autofill/autofill_popup_view_views.h" | 5 #include "chrome/browser/ui/views/autofill/autofill_popup_view_views.h" |
6 | 6 |
7 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 7 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
10 #include "ui/base/keycodes/keyboard_codes.h" | 10 #include "ui/base/keycodes/keyboard_codes.h" |
11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
13 #include "ui/gfx/display.h" | |
14 #include "ui/gfx/image/image.h" | 13 #include "ui/gfx/image/image.h" |
15 #include "ui/gfx/point.h" | 14 #include "ui/gfx/point.h" |
16 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
17 #include "ui/gfx/screen.h" | |
18 #include "ui/views/border.h" | 16 #include "ui/views/border.h" |
19 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
20 | 18 |
21 using WebKit::WebAutofillClient; | 19 using WebKit::WebAutofillClient; |
22 | 20 |
23 namespace { | 21 namespace { |
24 | 22 |
25 const SkColor kBorderColor = SkColorSetARGB(0xFF, 0xC7, 0xCA, 0xCE); | 23 const SkColor kBorderColor = SkColorSetARGB(0xFF, 0xC7, 0xCA, 0xCE); |
26 const SkColor kHoveredBackgroundColor = SkColorSetARGB(0xFF, 0xCD, 0xCD, 0xCD); | 24 const SkColor kHoveredBackgroundColor = SkColorSetARGB(0xFF, 0xCD, 0xCD, 0xCD); |
27 const SkColor kItemTextColor = SkColorSetARGB(0xFF, 0x7F, 0x7F, 0x7F); | 25 const SkColor kItemTextColor = SkColorSetARGB(0xFF, 0x7F, 0x7F, 0x7F); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // a weak pointer to hold the reference and don't have to worry about | 115 // a weak pointer to hold the reference and don't have to worry about |
118 // deletion. | 116 // deletion. |
119 views::Widget* widget = new views::Widget; | 117 views::Widget* widget = new views::Widget; |
120 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 118 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
121 params.delegate = this; | 119 params.delegate = this; |
122 params.can_activate = false; | 120 params.can_activate = false; |
123 params.transparent = true; | 121 params.transparent = true; |
124 params.parent = controller_->container_view(); | 122 params.parent = controller_->container_view(); |
125 widget->Init(params); | 123 widget->Init(params); |
126 widget->SetContentsView(this); | 124 widget->SetContentsView(this); |
| 125 widget->SetBounds(controller_->popup_bounds()); |
127 widget->Show(); | 126 widget->Show(); |
128 | 127 |
129 // Allow the popup to appear anywhere on the screen, since it may need | |
130 // to go beyond the bounds of the window. | |
131 // TODO(csharp): allow the popup to still appear on the border of | |
132 // two screens. | |
133 widget->SetBounds(gfx::Rect(GetScreenSize())); | |
134 | |
135 // Setup an observer to check for when the browser moves or changes size, | 128 // Setup an observer to check for when the browser moves or changes size, |
136 // since the popup should always be hidden in those cases. | 129 // since the popup should always be hidden in those cases. |
137 observing_widget_ = views::Widget::GetTopLevelWidgetForNativeView( | 130 observing_widget_ = views::Widget::GetTopLevelWidgetForNativeView( |
138 controller_->container_view()); | 131 controller_->container_view()); |
139 observing_widget_->AddObserver(this); | 132 observing_widget_->AddObserver(this); |
140 } | 133 } |
141 | 134 |
142 set_border(views::Border::CreateSolidBorder(kBorderThickness, kBorderColor)); | 135 set_border(views::Border::CreateSolidBorder(kBorderThickness, kBorderColor)); |
143 | 136 |
144 SetInitialBounds(); | |
145 UpdateBoundsAndRedrawPopup(); | 137 UpdateBoundsAndRedrawPopup(); |
146 } | 138 } |
147 | 139 |
148 void AutofillPopupViewViews::InvalidateRow(size_t row) { | 140 void AutofillPopupViewViews::InvalidateRow(size_t row) { |
149 SchedulePaintInRect(controller_->GetRowBounds(row)); | 141 SchedulePaintInRect(controller_->GetRowBounds(row)); |
150 } | 142 } |
151 | 143 |
152 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { | 144 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { |
153 SetBoundsRect(controller_->popup_bounds()); | 145 SetBoundsRect(controller_->popup_bounds()); |
154 SchedulePaintInRect(controller_->popup_bounds()); | 146 SchedulePaintInRect(controller_->popup_bounds()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 controller_->subtext_font(), | 206 controller_->subtext_font(), |
215 kItemTextColor, | 207 kItemTextColor, |
216 x_align_left + kEndPadding, | 208 x_align_left + kEndPadding, |
217 entry_rect.y(), | 209 entry_rect.y(), |
218 canvas->GetStringWidth(controller_->subtexts()[index], | 210 canvas->GetStringWidth(controller_->subtexts()[index], |
219 controller_->subtext_font()), | 211 controller_->subtext_font()), |
220 entry_rect.height(), | 212 entry_rect.height(), |
221 gfx::Canvas::TEXT_ALIGN_CENTER); | 213 gfx::Canvas::TEXT_ALIGN_CENTER); |
222 } | 214 } |
223 | 215 |
224 void AutofillPopupViewViews::SetInitialBounds() { | |
225 int bottom_of_field = controller_->element_bounds().bottom(); | |
226 int popup_height = controller_->GetPopupRequiredHeight(); | |
227 | |
228 // Find the correct top position of the popup so that it doesn't go off | |
229 // the screen. | |
230 int top_of_popup = 0; | |
231 if (GetScreenSize().height() < bottom_of_field + popup_height) { | |
232 // The popup must appear above the field. | |
233 top_of_popup = controller_->element_bounds().y() - popup_height; | |
234 } else { | |
235 // The popup can appear below the field. | |
236 top_of_popup = bottom_of_field; | |
237 } | |
238 | |
239 controller_->SetPopupBounds(gfx::Rect( | |
240 controller_->element_bounds().x(), | |
241 top_of_popup, | |
242 controller_->GetPopupRequiredWidth(), | |
243 popup_height)); | |
244 } | |
245 | |
246 gfx::Size AutofillPopupViewViews::GetScreenSize() { | |
247 gfx::Screen* screen = | |
248 gfx::Screen::GetScreenFor(controller_->container_view()); | |
249 gfx::Display display = | |
250 screen->GetDisplayNearestPoint(controller_->element_bounds().origin()); | |
251 | |
252 return display.GetSizeInPixel(); | |
253 } | |
254 | |
255 AutofillPopupView* AutofillPopupView::Create( | 216 AutofillPopupView* AutofillPopupView::Create( |
256 AutofillPopupController* controller) { | 217 AutofillPopupController* controller) { |
257 return new AutofillPopupViewViews(controller); | 218 return new AutofillPopupViewViews(controller); |
258 } | 219 } |
OLD | NEW |