Chromium Code Reviews| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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); |
| 127 widget->Show(); | 125 widget->Show(); |
| 128 | 126 |
| 129 // Allow the popup to appear anywhere on the screen, since it may need | 127 widget->SetBounds(controller_->popup_bounds()); |
|
Ilya Sherman
2013/01/15 01:34:45
nit: Should the bounds be set before the widget is
csharp
2013/01/15 22:06:39
Done.
| |
| 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 | 128 |
| 135 // Setup an observer to check for when the browser moves or changes size, | 129 // Setup an observer to check for when the browser moves or changes size, |
| 136 // since the popup should always be hidden in those cases. | 130 // since the popup should always be hidden in those cases. |
| 137 observing_widget_ = views::Widget::GetTopLevelWidgetForNativeView( | 131 observing_widget_ = views::Widget::GetTopLevelWidgetForNativeView( |
| 138 controller_->container_view()); | 132 controller_->container_view()); |
| 139 observing_widget_->AddObserver(this); | 133 observing_widget_->AddObserver(this); |
| 140 } | 134 } |
| 141 | 135 |
| 142 set_border(views::Border::CreateSolidBorder(kBorderThickness, kBorderColor)); | 136 set_border(views::Border::CreateSolidBorder(kBorderThickness, kBorderColor)); |
| 143 | 137 |
| 144 SetInitialBounds(); | |
| 145 UpdateBoundsAndRedrawPopup(); | 138 UpdateBoundsAndRedrawPopup(); |
| 146 } | 139 } |
| 147 | 140 |
| 148 void AutofillPopupViewViews::InvalidateRow(size_t row) { | 141 void AutofillPopupViewViews::InvalidateRow(size_t row) { |
| 149 SchedulePaintInRect(controller_->GetRowBounds(row)); | 142 SchedulePaintInRect(controller_->GetRowBounds(row)); |
| 150 } | 143 } |
| 151 | 144 |
| 152 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { | 145 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { |
| 153 SetBoundsRect(controller_->popup_bounds()); | 146 SetBoundsRect(controller_->popup_bounds()); |
| 154 SchedulePaintInRect(controller_->popup_bounds()); | 147 SchedulePaintInRect(controller_->popup_bounds()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 controller_->subtext_font(), | 207 controller_->subtext_font(), |
| 215 kItemTextColor, | 208 kItemTextColor, |
| 216 x_align_left + kEndPadding, | 209 x_align_left + kEndPadding, |
| 217 entry_rect.y(), | 210 entry_rect.y(), |
| 218 canvas->GetStringWidth(controller_->subtexts()[index], | 211 canvas->GetStringWidth(controller_->subtexts()[index], |
| 219 controller_->subtext_font()), | 212 controller_->subtext_font()), |
| 220 entry_rect.height(), | 213 entry_rect.height(), |
| 221 gfx::Canvas::TEXT_ALIGN_CENTER); | 214 gfx::Canvas::TEXT_ALIGN_CENTER); |
| 222 } | 215 } |
| 223 | 216 |
| 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( | 217 AutofillPopupView* AutofillPopupView::Create( |
| 256 AutofillPopupController* controller) { | 218 AutofillPopupController* controller) { |
| 257 return new AutofillPopupViewViews(controller); | 219 return new AutofillPopupViewViews(controller); |
| 258 } | 220 } |
| OLD | NEW |