Chromium Code Reviews| Index: chrome/browser/ui/views/autofill/autofill_popup_view_views.cc |
| diff --git a/chrome/browser/ui/views/autofill/autofill_popup_view_views.cc b/chrome/browser/ui/views/autofill/autofill_popup_view_views.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bed8b8c4bb406fe770c40de73c07642514363121 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/autofill/autofill_popup_view_views.cc |
| @@ -0,0 +1,95 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "autofill_popup_view_views.h" |
| + |
| +#include "chrome/browser/ui/views/autofill/autofill_external_delegate_views.h" |
| +#include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/browser/web_contents_view.h" |
| +#include "ui/gfx/canvas.h" |
| +#include "ui/gfx/rect.h" |
| +#include "ui/views/widget/widget.h" |
| + |
| +namespace { |
| +const SkColor kPopupBackground = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00); |
| +} // namespace |
| + |
| +class AutofillPopupViewViews::AutofillPopupWidget |
|
sky
2012/08/28 15:51:37
The ownership is still slightly wrong here. Rememb
csharp
2012/08/29 17:19:38
Ok, I removed the weak_ptr support. InvalidateView
|
| + : public views::Widget, |
| + public base::SupportsWeakPtr<AutofillPopupWidget> { |
| + public: |
| + AutofillPopupWidget() {} |
| + virtual ~AutofillPopupWidget() {} |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(AutofillPopupWidget); |
| +}; |
| + |
| +AutofillPopupViewViews::AutofillPopupViewViews( |
| + content::WebContents* web_contents, |
| + AutofillExternalDelegateViews* external_delegate) |
| + : AutofillPopupView(web_contents, external_delegate), |
| + popup_closing_(false), |
| + external_delegate_(external_delegate), |
| + web_contents_(web_contents) { |
| +} |
| + |
| +AutofillPopupViewViews::~AutofillPopupViewViews() { |
| + if (!popup_closing_ && popup_.get()) |
| + popup_->Close(); |
| + external_delegate_->InvalidateView(); |
| +} |
| + |
| +void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
| + // TODO(csharp): Properly draw the popup. |
| + canvas->DrawColor(kPopupBackground); |
| +} |
| + |
| +void AutofillPopupViewViews::WindowClosing() { |
| + popup_closing_ = true; |
| +} |
| + |
| +void AutofillPopupViewViews::ShowInternal() { |
| + if (!popup_.get()) { |
| + // The widget is destroyed by the corresponding NativeWidget, so we use |
| + // a weak pointer to hold the reference and don't have to worry about |
| + // deletion. |
| + popup_ = (new AutofillPopupWidget)->AsWeakPtr(); |
| + views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| + params.delegate = this; |
| + params.can_activate = false; |
| + params.transparent = true; |
| + params.parent = web_contents_->GetView()->GetTopLevelNativeWindow(); |
| + popup_->Init(params); |
| + popup_->SetContentsView(this); |
| + popup_->Show(); |
| + |
| + gfx::Rect client_area; |
| + web_contents_->GetContainerBounds(&client_area); |
| + popup_->SetBounds(client_area); |
| + } |
| + |
| + ResizePopup(); |
| + |
| + web_contents_->GetRenderViewHost()->AddKeyboardListener(this); |
| +} |
| + |
| +void AutofillPopupViewViews::HideInternal() { |
| + web_contents_->GetRenderViewHost()->RemoveKeyboardListener(this); |
| + |
| + if (popup_.get()) |
| + popup_->Close(); |
| +} |
| + |
| +void AutofillPopupViewViews::InvalidateRow(size_t row) { |
| + // TODO(csharp): invalidate this row. |
| +} |
| + |
| +void AutofillPopupViewViews::ResizePopup() { |
| + gfx::Rect popup_bounds = element_bounds(); |
| + popup_bounds.set_y(popup_bounds.y() + popup_bounds.height()); |
| + |
| + SetBoundsRect(popup_bounds); |
| +} |