OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/link_disambiguation/link_disambiguation_popup.
h" | 5 #include "chrome/browser/ui/views/link_disambiguation/link_disambiguation_popup.
h" |
6 | 6 |
7 #include "ui/aura/client/screen_position_client.h" | 7 #include "ui/aura/client/screen_position_client.h" |
8 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
9 #include "ui/events/event_processor.h" | 9 #include "ui/events/event_processor.h" |
10 #include "ui/events/event_utils.h" | 10 #include "ui/events/event_utils.h" |
11 #include "ui/events/gesture_event_details.h" | 11 #include "ui/events/gesture_event_details.h" |
12 #include "ui/gfx/display.h" | 12 #include "ui/gfx/display.h" |
13 #include "ui/gfx/image/image.h" | 13 #include "ui/gfx/image/image.h" |
14 #include "ui/gfx/image/image_skia.h" | 14 #include "ui/gfx/image/image_skia.h" |
15 #include "ui/gfx/screen.h" | 15 #include "ui/gfx/screen.h" |
16 #include "ui/views/bubble/bubble_delegate.h" | 16 #include "ui/views/bubble/bubble_delegate.h" |
17 #include "ui/views/controls/image_view.h" | 17 #include "ui/views/controls/image_view.h" |
18 | 18 |
19 class LinkDisambiguationPopup::ZoomBubbleView | 19 class LinkDisambiguationPopup::ZoomBubbleView |
20 : public views::BubbleDelegateView { | 20 : public views::BubbleDelegateView { |
21 public: | 21 public: |
22 ZoomBubbleView(views::Widget* top_level_widget, | 22 ZoomBubbleView(views::Widget* top_level_widget, |
23 const gfx::Rect& target_rect, | 23 const gfx::Rect& target_rect, |
24 const gfx::ImageSkia* zoomed_skia_image, | 24 const gfx::ImageSkia* zoomed_skia_image, |
25 const aura::Window* content, | |
26 LinkDisambiguationPopup* popup, | 25 LinkDisambiguationPopup* popup, |
27 const base::Callback<void(ui::GestureEvent*)>& gesture_cb, | 26 const base::Callback<void(ui::GestureEvent*)>& gesture_cb, |
28 const base::Callback<void(ui::MouseEvent*)>& mouse_cb); | 27 const base::Callback<void(ui::MouseEvent*)>& mouse_cb); |
29 | 28 |
30 void Close(); | 29 void Close(); |
31 | 30 |
32 private: | 31 private: |
33 // views::View overrides | 32 // views::View overrides |
34 gfx::Size GetPreferredSize() const override; | 33 gfx::Size GetPreferredSize() const override; |
35 void OnGestureEvent(ui::GestureEvent* event) override; | 34 void OnGestureEvent(ui::GestureEvent* event) override; |
36 void OnMouseEvent(ui::MouseEvent* event) override; | 35 void OnMouseEvent(ui::MouseEvent* event) override; |
37 | 36 |
38 // WidgetObserver overrides | 37 // WidgetObserver overrides |
39 void OnWidgetClosing(views::Widget* widget) override; | 38 void OnWidgetClosing(views::Widget* widget) override; |
40 | 39 |
41 const float scale_; | 40 const float scale_; |
42 const aura::Window* content_; | |
43 const base::Callback<void(ui::GestureEvent*)> gesture_cb_; | 41 const base::Callback<void(ui::GestureEvent*)> gesture_cb_; |
44 const base::Callback<void(ui::MouseEvent*)> mouse_cb_; | 42 const base::Callback<void(ui::MouseEvent*)> mouse_cb_; |
45 LinkDisambiguationPopup* popup_; | 43 LinkDisambiguationPopup* popup_; |
46 const gfx::Rect target_rect_; | 44 const gfx::Rect target_rect_; |
47 | 45 |
48 DISALLOW_COPY_AND_ASSIGN(ZoomBubbleView); | 46 DISALLOW_COPY_AND_ASSIGN(ZoomBubbleView); |
49 }; | 47 }; |
50 | 48 |
51 LinkDisambiguationPopup::ZoomBubbleView::ZoomBubbleView( | 49 LinkDisambiguationPopup::ZoomBubbleView::ZoomBubbleView( |
52 views::Widget* top_level_widget, | 50 views::Widget* top_level_widget, |
53 const gfx::Rect& target_rect, | 51 const gfx::Rect& target_rect, |
54 const gfx::ImageSkia* zoomed_skia_image, | 52 const gfx::ImageSkia* zoomed_skia_image, |
55 const aura::Window* content, | |
56 LinkDisambiguationPopup* popup, | 53 LinkDisambiguationPopup* popup, |
57 const base::Callback<void(ui::GestureEvent*)>& gesture_cb, | 54 const base::Callback<void(ui::GestureEvent*)>& gesture_cb, |
58 const base::Callback<void(ui::MouseEvent*)>& mouse_cb) | 55 const base::Callback<void(ui::MouseEvent*)>& mouse_cb) |
59 : BubbleDelegateView( | 56 : BubbleDelegateView( |
60 top_level_widget ? top_level_widget->GetContentsView() : nullptr, | 57 top_level_widget ? top_level_widget->GetContentsView() : nullptr, |
61 views::BubbleBorder::FLOAT), | 58 views::BubbleBorder::FLOAT), |
62 scale_(static_cast<float>(zoomed_skia_image->width()) / | 59 scale_(static_cast<float>(zoomed_skia_image->width()) / |
63 static_cast<float>(target_rect.width())), | 60 static_cast<float>(target_rect.width())), |
64 content_(content), | |
65 gesture_cb_(gesture_cb), | 61 gesture_cb_(gesture_cb), |
66 mouse_cb_(mouse_cb), | 62 mouse_cb_(mouse_cb), |
67 popup_(popup), | 63 popup_(popup), |
68 target_rect_(target_rect) { | 64 target_rect_(target_rect) { |
69 views::ImageView* image_view = new views::ImageView(); | 65 views::ImageView* image_view = new views::ImageView(); |
70 image_view->SetBounds( | 66 image_view->SetBounds( |
71 0, 0, zoomed_skia_image->width(), zoomed_skia_image->height()); | 67 0, 0, zoomed_skia_image->width(), zoomed_skia_image->height()); |
72 image_view->SetImage(zoomed_skia_image); | 68 image_view->SetImage(zoomed_skia_image); |
73 | 69 |
74 AddChildView(image_view); | 70 AddChildView(image_view); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 const gfx::Rect& target_rect, | 155 const gfx::Rect& target_rect, |
160 const gfx::NativeView content, | 156 const gfx::NativeView content, |
161 const base::Callback<void(ui::GestureEvent*)>& gesture_cb, | 157 const base::Callback<void(ui::GestureEvent*)>& gesture_cb, |
162 const base::Callback<void(ui::MouseEvent*)>& mouse_cb) { | 158 const base::Callback<void(ui::MouseEvent*)>& mouse_cb) { |
163 content_ = content; | 159 content_ = content; |
164 | 160 |
165 view_ = new ZoomBubbleView( | 161 view_ = new ZoomBubbleView( |
166 top_level_widget, | 162 top_level_widget, |
167 target_rect, | 163 target_rect, |
168 gfx::Image::CreateFrom1xBitmap(zoomed_bitmap).ToImageSkia(), | 164 gfx::Image::CreateFrom1xBitmap(zoomed_bitmap).ToImageSkia(), |
169 content_, | |
170 this, | 165 this, |
171 gesture_cb, | 166 gesture_cb, |
172 mouse_cb); | 167 mouse_cb); |
173 | 168 |
174 // Center the zoomed bubble over the target rectangle, constrained to the | 169 // Center the zoomed bubble over the target rectangle, constrained to the |
175 // work area in the current display. Since |target_rect| is provided in | 170 // work area in the current display. Since |target_rect| is provided in |
176 // |content_| coordinate system, we must convert it into Screen coordinates | 171 // |content_| coordinate system, we must convert it into Screen coordinates |
177 // for correct window positioning. | 172 // for correct window positioning. |
178 aura::client::ScreenPositionClient* screen_position_client = | 173 aura::client::ScreenPositionClient* screen_position_client = |
179 aura::client::GetScreenPositionClient(content_->GetRootWindow()); | 174 aura::client::GetScreenPositionClient(content_->GetRootWindow()); |
(...skipping 16 matching lines...) Expand all Loading... |
196 void LinkDisambiguationPopup::Close() { | 191 void LinkDisambiguationPopup::Close() { |
197 if (view_) { | 192 if (view_) { |
198 view_->Close(); | 193 view_->Close(); |
199 view_ = NULL; | 194 view_ = NULL; |
200 } | 195 } |
201 } | 196 } |
202 | 197 |
203 void LinkDisambiguationPopup::InvalidateBubbleView() { | 198 void LinkDisambiguationPopup::InvalidateBubbleView() { |
204 view_ = NULL; | 199 view_ = NULL; |
205 } | 200 } |
OLD | NEW |