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/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 class AutofillPopupViewViews::AutofillPopupWidget | |
|
sky
2012/08/16 23:02:01
Why do you need this class?
When the popup is del
csharp
2012/08/20 20:59:00
I wasn't able to get the popup to be visible witho
| |
| 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 AutofillExternalDelegateViews* external_delegate) | |
| 33 : AutofillPopupView(web_contents, external_delegate), | |
| 34 external_delegate_(external_delegate), | |
| 35 web_contents_(web_contents) { | |
| 36 } | |
| 37 | |
| 38 AutofillPopupViewViews::~AutofillPopupViewViews() { | |
| 39 external_delegate_->InvalidateView(); | |
| 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_) { | |
| 49 // The widget is destroyed by the corresponding NativeWidget, so we use | |
| 50 // a weak pointer to hold the reference and don't have to worry about | |
| 51 // deletion. | |
| 52 popup_ = (new AutofillPopupWidget)->AsWeakPtr(); | |
| 53 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | |
| 54 params.can_activate = false; | |
| 55 params.transparent = true; | |
| 56 params.parent = web_contents_->GetView()->GetTopLevelNativeWindow(); | |
| 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 web_contents_->GetRenderViewHost()->AddKeyboardListener(this); | |
| 69 } | |
| 70 | |
| 71 void AutofillPopupViewViews::HideInternal() { | |
| 72 web_contents_->GetRenderViewHost()->RemoveKeyboardListener(this); | |
| 73 | |
| 74 popup_->Hide(); | |
|
sky
2012/08/16 23:02:01
You never close the popup_ and therefor its leakin
csharp
2012/08/20 20:59:00
Added close to popup in the deconstructor
| |
| 75 SetVisible(false); | |
| 76 } | |
| 77 | |
| 78 void AutofillPopupViewViews::InvalidateRow(size_t row) { | |
| 79 // TODO(csharp): invalidate this row. | |
| 80 } | |
| 81 | |
| 82 void AutofillPopupViewViews::ResizePopup() { | |
| 83 gfx::Rect popup_bounds = element_bounds(); | |
| 84 popup_bounds.set_y(popup_bounds.y() + popup_bounds.height()); | |
| 85 | |
| 86 SetBoundsRect(popup_bounds); | |
| 87 } | |
| OLD | NEW |