Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "autofill_popup_view_views.h" | |
| 6 | |
| 7 #include "chrome/browser/autofill/autofill_external_delegate.h" | |
| 8 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 9 #include "content/public/browser/render_view_host.h" | |
| 10 #include "content/public/browser/web_contents.h" | |
| 11 #include "content/public/browser/web_contents_view.h" | |
| 12 #include "ui/gfx/canvas.h" | |
| 13 #include "ui/gfx/rect.h" | |
| 14 | |
| 15 namespace { | |
| 16 const SkColor kPopupBackground = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00); | |
| 17 } // namespace | |
| 18 | |
| 19 class AutofillPopupViewViews::AutofillPopupWidget | |
| 20 : public views::Widget, | |
| 21 public base::SupportsWeakPtr<AutofillPopupWidget> { | |
| 22 public: | |
| 23 AutofillPopupWidget() {} | |
| 24 virtual ~AutofillPopupWidget() {} | |
| 25 | |
| 26 private: | |
| 27 DISALLOW_COPY_AND_ASSIGN(AutofillPopupWidget); | |
| 28 }; | |
| 29 | |
| 30 AutofillPopupViewViews::AutofillPopupViewViews( | |
| 31 content::WebContents* web_contents, | |
| 32 AutofillExternalDelegate* external_delegate) | |
| 33 : AutofillPopupView(web_contents, external_delegate), | |
| 34 render_view_host_(web_contents->GetRenderViewHost()), | |
| 35 web_contents_(web_contents) { | |
| 36 SetVisible(false); | |
| 37 } | |
| 38 | |
| 39 AutofillPopupViewViews::~AutofillPopupViewViews() { | |
| 40 } | |
| 41 | |
| 42 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { | |
| 43 // TODO(csharp): Properly draw the popup. | |
| 44 canvas->DrawColor(kPopupBackground); | |
| 45 } | |
| 46 | |
| 47 void AutofillPopupViewViews::ShowInternal() { | |
| 48 if (popup_ == NULL) { | |
|
Ilya Sherman
2012/08/14 05:12:09
nit: if (!popup_) {
csharp
2012/08/14 19:06:13
Done.
| |
| 49 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow( | |
| 50 web_contents_->GetView()->GetTopLevelNativeWindow()); | |
| 51 | |
| 52 popup_ = (new AutofillPopupWidget)->AsWeakPtr(); | |
|
Ilya Sherman
2012/08/14 05:12:09
nit: Please add a brief comment here about the lif
csharp
2012/08/14 19:06:13
Comment added, let me know if it needs more detail
| |
| 53 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | |
| 54 params.can_activate = false; | |
| 55 params.transparent = true; | |
| 56 params.parent_widget = browser_view->GetWidget(); | |
| 57 popup_->Init(params); | |
| 58 popup_->SetContentsView(this); | |
| 59 popup_->Show(); | |
| 60 | |
| 61 gfx::Rect client_area; | |
| 62 web_contents_->GetContainerBounds(&client_area); | |
| 63 popup_->SetBounds(client_area); | |
| 64 } | |
| 65 | |
| 66 ResizePopup(); | |
| 67 | |
| 68 render_view_host_->AddKeyboardListener(this); | |
| 69 | |
| 70 SetVisible(true); | |
| 71 } | |
| 72 | |
| 73 void AutofillPopupViewViews::HideInternal() { | |
| 74 render_view_host_->RemoveKeyboardListener(this); | |
| 75 | |
| 76 SetVisible(false); | |
| 77 } | |
| 78 | |
| 79 void AutofillPopupViewViews::InvalidateRow(size_t row) { | |
| 80 // TODO(csharp): invalidate this row. | |
| 81 } | |
| 82 | |
| 83 void AutofillPopupViewViews::ResizePopup() { | |
| 84 gfx::Rect popup_bounds = element_bounds(); | |
| 85 popup_bounds.set_y(popup_bounds.y() + element_bounds().height()); | |
|
Ilya Sherman
2012/08/14 05:12:09
nit: It's a little weird to use popup_bounds.y() a
csharp
2012/08/14 19:06:13
Done.
| |
| 86 | |
| 87 SetBoundsRect(popup_bounds); | |
| 88 } | |
| OLD | NEW |