| 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/ui/views/autofill/autofill_external_delegate_views.h" |
| 8 #include "content/public/browser/render_view_host.h" |
| 9 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/browser/web_contents_view.h" |
| 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/rect.h" |
| 13 #include "ui/views/widget/widget.h" |
| 14 |
| 15 namespace { |
| 16 const SkColor kPopupBackground = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00); |
| 17 } // namespace |
| 18 |
| 19 AutofillPopupViewViews::AutofillPopupViewViews( |
| 20 content::WebContents* web_contents, |
| 21 AutofillExternalDelegateViews* external_delegate) |
| 22 : AutofillPopupView(web_contents, external_delegate), |
| 23 popup_closing_(false), |
| 24 external_delegate_(external_delegate), |
| 25 web_contents_(web_contents) { |
| 26 } |
| 27 |
| 28 AutofillPopupViewViews::~AutofillPopupViewViews() { |
| 29 external_delegate_->InvalidateView(); |
| 30 } |
| 31 |
| 32 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
| 33 // TODO(csharp): Properly draw the popup. |
| 34 canvas->DrawColor(kPopupBackground); |
| 35 } |
| 36 |
| 37 void AutofillPopupViewViews::WindowClosing() { |
| 38 popup_closing_ = true; |
| 39 } |
| 40 |
| 41 void AutofillPopupViewViews::ShowInternal() { |
| 42 if (!GetWidget()) { |
| 43 // The widget is destroyed by the corresponding NativeWidget, so we use |
| 44 // a weak pointer to hold the reference and don't have to worry about |
| 45 // deletion. |
| 46 views::Widget* widget = new views::Widget; |
| 47 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 48 params.delegate = this; |
| 49 params.can_activate = false; |
| 50 params.transparent = true; |
| 51 params.parent = web_contents_->GetView()->GetTopLevelNativeWindow(); |
| 52 widget->Init(params); |
| 53 widget->SetContentsView(this); |
| 54 widget->Show(); |
| 55 |
| 56 gfx::Rect client_area; |
| 57 web_contents_->GetContainerBounds(&client_area); |
| 58 widget->SetBounds(client_area); |
| 59 } |
| 60 |
| 61 ResizePopup(); |
| 62 |
| 63 web_contents_->GetRenderViewHost()->AddKeyboardListener(this); |
| 64 } |
| 65 |
| 66 void AutofillPopupViewViews::HideInternal() { |
| 67 GetWidget()->Close(); |
| 68 web_contents_->GetRenderViewHost()->RemoveKeyboardListener(this); |
| 69 } |
| 70 |
| 71 void AutofillPopupViewViews::InvalidateRow(size_t row) { |
| 72 // TODO(csharp): invalidate this row. |
| 73 } |
| 74 |
| 75 void AutofillPopupViewViews::ResizePopup() { |
| 76 gfx::Rect popup_bounds = element_bounds(); |
| 77 popup_bounds.set_y(popup_bounds.y() + popup_bounds.height()); |
| 78 |
| 79 SetBoundsRect(popup_bounds); |
| 80 } |
| OLD | NEW |