Commit 34488c00 authored by estade's avatar estade Committed by Commit bot

Convert LinkDisambiguationPopup to BubbleDialogDelegateView

BUG=585312

Review URL: https://codereview.chromium.org/1894173002

Cr-Commit-Position: refs/heads/master@{#388597}
parent 7cf8148f
...@@ -14,11 +14,11 @@ ...@@ -14,11 +14,11 @@
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "ui/views/bubble/bubble_delegate.h" #include "ui/views/bubble/bubble_dialog_delegate.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
class LinkDisambiguationPopup::ZoomBubbleView class LinkDisambiguationPopup::ZoomBubbleView
: public views::BubbleDelegateView { : public views::BubbleDialogDelegateView {
public: public:
ZoomBubbleView(views::Widget* top_level_widget, ZoomBubbleView(views::Widget* top_level_widget,
const gfx::Rect& target_rect, const gfx::Rect& target_rect,
...@@ -27,17 +27,18 @@ class LinkDisambiguationPopup::ZoomBubbleView ...@@ -27,17 +27,18 @@ class LinkDisambiguationPopup::ZoomBubbleView
const base::Callback<void(ui::GestureEvent*)>& gesture_cb, const base::Callback<void(ui::GestureEvent*)>& gesture_cb,
const base::Callback<void(ui::MouseEvent*)>& mouse_cb); const base::Callback<void(ui::MouseEvent*)>& mouse_cb);
void Close();
private: private:
// views::View overrides // views::View overrides
gfx::Size GetPreferredSize() const override; gfx::Size GetPreferredSize() const override;
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
void OnMouseEvent(ui::MouseEvent* event) override; void OnMouseEvent(ui::MouseEvent* event) override;
// WidgetObserver overrides // views::WidgetObserver overrides
void OnWidgetClosing(views::Widget* widget) override; void OnWidgetClosing(views::Widget* widget) override;
// views::BubbleDialogDelegate overrides
int GetDialogButtons() const override;
const float scale_; const float scale_;
const base::Callback<void(ui::GestureEvent*)> gesture_cb_; const base::Callback<void(ui::GestureEvent*)> gesture_cb_;
const base::Callback<void(ui::MouseEvent*)> mouse_cb_; const base::Callback<void(ui::MouseEvent*)> mouse_cb_;
...@@ -54,7 +55,7 @@ LinkDisambiguationPopup::ZoomBubbleView::ZoomBubbleView( ...@@ -54,7 +55,7 @@ LinkDisambiguationPopup::ZoomBubbleView::ZoomBubbleView(
LinkDisambiguationPopup* popup, LinkDisambiguationPopup* popup,
const base::Callback<void(ui::GestureEvent*)>& gesture_cb, const base::Callback<void(ui::GestureEvent*)>& gesture_cb,
const base::Callback<void(ui::MouseEvent*)>& mouse_cb) const base::Callback<void(ui::MouseEvent*)>& mouse_cb)
: BubbleDelegateView( : BubbleDialogDelegateView(
top_level_widget ? top_level_widget->GetContentsView() : nullptr, top_level_widget ? top_level_widget->GetContentsView() : nullptr,
views::BubbleBorder::FLOAT), views::BubbleBorder::FLOAT),
scale_(static_cast<float>(zoomed_skia_image->width()) / scale_(static_cast<float>(zoomed_skia_image->width()) /
...@@ -64,18 +65,11 @@ LinkDisambiguationPopup::ZoomBubbleView::ZoomBubbleView( ...@@ -64,18 +65,11 @@ LinkDisambiguationPopup::ZoomBubbleView::ZoomBubbleView(
popup_(popup), popup_(popup),
target_rect_(target_rect) { target_rect_(target_rect) {
views::ImageView* image_view = new views::ImageView(); views::ImageView* image_view = new views::ImageView();
image_view->SetBounds( image_view->SetSize(zoomed_skia_image->size());
0, 0, zoomed_skia_image->width(), zoomed_skia_image->height());
image_view->SetImage(zoomed_skia_image); image_view->SetImage(zoomed_skia_image);
AddChildView(image_view); AddChildView(image_view);
views::BubbleDelegateView::CreateBubble(this); views::BubbleDialogDelegateView::CreateBubble(this);
}
void LinkDisambiguationPopup::ZoomBubbleView::Close() {
if (GetWidget())
GetWidget()->Close();
} }
gfx::Size LinkDisambiguationPopup::ZoomBubbleView::GetPreferredSize() const { gfx::Size LinkDisambiguationPopup::ZoomBubbleView::GetPreferredSize() const {
...@@ -99,7 +93,7 @@ void LinkDisambiguationPopup::ZoomBubbleView::OnMouseEvent( ...@@ -99,7 +93,7 @@ void LinkDisambiguationPopup::ZoomBubbleView::OnMouseEvent(
// If user completed a click we can close the window. // If user completed a click we can close the window.
if (event->type() == ui::EventType::ET_MOUSE_RELEASED) if (event->type() == ui::EventType::ET_MOUSE_RELEASED)
Close(); GetWidget()->Close();
} }
void LinkDisambiguationPopup::ZoomBubbleView::OnGestureEvent( void LinkDisambiguationPopup::ZoomBubbleView::OnGestureEvent(
...@@ -108,7 +102,7 @@ void LinkDisambiguationPopup::ZoomBubbleView::OnGestureEvent( ...@@ -108,7 +102,7 @@ void LinkDisambiguationPopup::ZoomBubbleView::OnGestureEvent(
// ourselves, as perhaps the user has decided on a different part of the page. // ourselves, as perhaps the user has decided on a different part of the page.
if (event->location().x() > bounds().width() || if (event->location().x() > bounds().width() ||
event->location().y() > bounds().height()) { event->location().y() > bounds().height()) {
Close(); GetWidget()->Close();
return; return;
} }
...@@ -135,7 +129,7 @@ void LinkDisambiguationPopup::ZoomBubbleView::OnGestureEvent( ...@@ -135,7 +129,7 @@ void LinkDisambiguationPopup::ZoomBubbleView::OnGestureEvent(
// If we completed a tap we close ourselves, as the web content will navigate // If we completed a tap we close ourselves, as the web content will navigate
// if the user hit a link. // if the user hit a link.
if (event->type() == ui::EventType::ET_GESTURE_TAP) if (event->type() == ui::EventType::ET_GESTURE_TAP)
Close(); GetWidget()->Close();
} }
void LinkDisambiguationPopup::ZoomBubbleView::OnWidgetClosing( void LinkDisambiguationPopup::ZoomBubbleView::OnWidgetClosing(
...@@ -143,6 +137,10 @@ void LinkDisambiguationPopup::ZoomBubbleView::OnWidgetClosing( ...@@ -143,6 +137,10 @@ void LinkDisambiguationPopup::ZoomBubbleView::OnWidgetClosing(
popup_->InvalidateBubbleView(); popup_->InvalidateBubbleView();
} }
int LinkDisambiguationPopup::ZoomBubbleView::GetDialogButtons() const {
return ui::DIALOG_BUTTON_NONE;
}
LinkDisambiguationPopup::LinkDisambiguationPopup() LinkDisambiguationPopup::LinkDisambiguationPopup()
: content_(NULL), : content_(NULL),
view_(NULL) { view_(NULL) {
...@@ -192,12 +190,10 @@ void LinkDisambiguationPopup::Show( ...@@ -192,12 +190,10 @@ void LinkDisambiguationPopup::Show(
} }
void LinkDisambiguationPopup::Close() { void LinkDisambiguationPopup::Close() {
if (view_) { if (view_ && view_->GetWidget())
view_->Close(); view_->GetWidget()->Close();
view_ = NULL;
}
} }
void LinkDisambiguationPopup::InvalidateBubbleView() { void LinkDisambiguationPopup::InvalidateBubbleView() {
view_ = NULL; view_ = nullptr;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment