OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/location_bar/zoom_bubble_view.h" | 5 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/chrome_page_zoom.h" | 10 #include "chrome/browser/chrome_page_zoom.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
13 #include "chrome/browser/ui/browser_tabstrip.h" | 13 #include "chrome/browser/ui/browser_tabstrip.h" |
14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
15 #include "chrome/browser/ui/views/frame/browser_view.h" | 15 #include "chrome/browser/ui/views/frame/browser_view.h" |
16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
17 #include "chrome/browser/ui/views/location_bar/zoom_view.h" | 17 #include "chrome/browser/ui/views/location_bar/zoom_view.h" |
18 #include "chrome/browser/ui/zoom/zoom_controller.h" | |
19 #include "chrome/common/extensions/api/extension_action/action_info.h" | 18 #include "chrome/common/extensions/api/extension_action/action_info.h" |
20 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| 20 #include "components/ui/zoom/zoom_controller.h" |
21 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 22 #include "extensions/browser/extension_zoom_request_client.h" |
22 #include "extensions/common/manifest_handlers/icons_handler.h" | 23 #include "extensions/common/manifest_handlers/icons_handler.h" |
23 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/gfx/favicon_size.h" | 27 #include "ui/gfx/favicon_size.h" |
27 #include "ui/views/controls/button/image_button.h" | 28 #include "ui/views/controls/button/image_button.h" |
28 #include "ui/views/controls/button/label_button.h" | 29 #include "ui/views/controls/button/label_button.h" |
29 #include "ui/views/controls/separator.h" | 30 #include "ui/views/controls/separator.h" |
30 #include "ui/views/layout/grid_layout.h" | 31 #include "ui/views/layout/grid_layout.h" |
31 #include "ui/views/layout/layout_constants.h" | 32 #include "ui/views/layout/layout_constants.h" |
(...skipping 20 matching lines...) Expand all Loading... |
52 DCHECK(browser && browser->window() && browser->fullscreen_controller()); | 53 DCHECK(browser && browser->window() && browser->fullscreen_controller()); |
53 | 54 |
54 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 55 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
55 bool is_fullscreen = browser_view->IsFullscreen(); | 56 bool is_fullscreen = browser_view->IsFullscreen(); |
56 bool anchor_to_view = !is_fullscreen || | 57 bool anchor_to_view = !is_fullscreen || |
57 browser_view->immersive_mode_controller()->IsRevealed(); | 58 browser_view->immersive_mode_controller()->IsRevealed(); |
58 views::View* anchor_view = anchor_to_view ? | 59 views::View* anchor_view = anchor_to_view ? |
59 browser_view->GetLocationBarView()->zoom_view() : NULL; | 60 browser_view->GetLocationBarView()->zoom_view() : NULL; |
60 | 61 |
61 // Find the extension that initiated the zoom change, if any. | 62 // Find the extension that initiated the zoom change, if any. |
62 ZoomController* zoom_controller = | 63 ui_zoom::ZoomController* zoom_controller = |
63 ZoomController::FromWebContents(web_contents); | 64 ui_zoom::ZoomController::FromWebContents(web_contents); |
64 const extensions::Extension* extension = zoom_controller->last_extension(); | 65 const ui_zoom::ZoomRequestClient* client = zoom_controller->last_client(); |
65 | 66 |
66 // If the bubble is already showing in this window and the zoom change was not | 67 // If the bubble is already showing in this window and the zoom change was not |
67 // initiated by an extension, then the bubble can be reused and only the label | 68 // initiated by an extension, then the bubble can be reused and only the label |
68 // text needs to be updated. | 69 // text needs to be updated. |
69 if (zoom_bubble_ && | 70 if (zoom_bubble_ && zoom_bubble_->GetAnchorView() == anchor_view && !client) { |
70 zoom_bubble_->GetAnchorView() == anchor_view && | |
71 !extension) { | |
72 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_); | 71 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_); |
73 zoom_bubble_->Refresh(); | 72 zoom_bubble_->Refresh(); |
74 return; | 73 return; |
75 } | 74 } |
76 | 75 |
77 // If the bubble is already showing but in a different tab, the current | 76 // If the bubble is already showing but in a different tab, the current |
78 // bubble must be closed and a new one created. | 77 // bubble must be closed and a new one created. |
79 CloseBubble(); | 78 CloseBubble(); |
80 | 79 |
81 zoom_bubble_ = new ZoomBubbleView(anchor_view, | 80 zoom_bubble_ = new ZoomBubbleView(anchor_view, |
82 web_contents, | 81 web_contents, |
83 auto_close, | 82 auto_close, |
84 browser_view->immersive_mode_controller(), | 83 browser_view->immersive_mode_controller(), |
85 browser->fullscreen_controller()); | 84 browser->fullscreen_controller()); |
86 | 85 |
87 // If the zoom change was initiated by an extension, capture the relevent | 86 // If the zoom change was initiated by an extension, capture the relevent |
88 // information from it. | 87 // information from it. |
89 if (extension) | 88 if (client) { |
90 zoom_bubble_->SetExtensionInfo(extension); | 89 zoom_bubble_->SetExtensionInfo( |
| 90 static_cast<const extensions::ExtensionZoomRequestClient*>(client) |
| 91 ->extension()); |
| 92 } |
91 | 93 |
92 // If we do not have an anchor view, parent the bubble to the content area. | 94 // If we do not have an anchor view, parent the bubble to the content area. |
93 if (!anchor_to_view) | 95 if (!anchor_to_view) |
94 zoom_bubble_->set_parent_window(web_contents->GetTopLevelNativeWindow()); | 96 zoom_bubble_->set_parent_window(web_contents->GetTopLevelNativeWindow()); |
95 | 97 |
96 views::BubbleDelegateView::CreateBubble(zoom_bubble_); | 98 views::BubbleDelegateView::CreateBubble(zoom_bubble_); |
97 | 99 |
98 // Adjust for fullscreen after creation as it relies on the content size. | 100 // Adjust for fullscreen after creation as it relies on the content size. |
99 if (is_fullscreen) | 101 if (is_fullscreen) |
100 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); | 102 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 161 |
160 // TODO(dbeam): should RTL logic be done in views::BubbleDelegateView? | 162 // TODO(dbeam): should RTL logic be done in views::BubbleDelegateView? |
161 const size_t bubble_half_width = width() / 2; | 163 const size_t bubble_half_width = width() / 2; |
162 const int x_pos = base::i18n::IsRTL() ? | 164 const int x_pos = base::i18n::IsRTL() ? |
163 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : | 165 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : |
164 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; | 166 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; |
165 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); | 167 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); |
166 } | 168 } |
167 | 169 |
168 void ZoomBubbleView::Refresh() { | 170 void ZoomBubbleView::Refresh() { |
169 ZoomController* zoom_controller = | 171 ui_zoom::ZoomController* zoom_controller = |
170 ZoomController::FromWebContents(web_contents_); | 172 ui_zoom::ZoomController::FromWebContents(web_contents_); |
171 int zoom_percent = zoom_controller->GetZoomPercent(); | 173 int zoom_percent = zoom_controller->GetZoomPercent(); |
172 label_->SetText( | 174 label_->SetText( |
173 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent)); | 175 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent)); |
174 StartTimerIfNecessary(); | 176 StartTimerIfNecessary(); |
175 } | 177 } |
176 | 178 |
177 void ZoomBubbleView::Close() { | 179 void ZoomBubbleView::Close() { |
178 // Widget's Close() is async, but we don't want to use zoom_bubble_ after | 180 // Widget's Close() is async, but we don't want to use zoom_bubble_ after |
179 // this. Additionally web_contents_ may have been destroyed. | 181 // this. Additionally web_contents_ may have been destroyed. |
180 zoom_bubble_ = NULL; | 182 zoom_bubble_ = NULL; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 image_button_ = new views::ImageButton(this); | 308 image_button_ = new views::ImageButton(this); |
307 image_button_->SetTooltipText(l10n_util::GetStringFUTF16( | 309 image_button_->SetTooltipText(l10n_util::GetStringFUTF16( |
308 IDS_TOOLTIP_ZOOM_EXTENSION_ICON, | 310 IDS_TOOLTIP_ZOOM_EXTENSION_ICON, |
309 base::UTF8ToUTF16(extension_info_.name))); | 311 base::UTF8ToUTF16(extension_info_.name))); |
310 image_button_->SetImage(views::Button::STATE_NORMAL, | 312 image_button_->SetImage(views::Button::STATE_NORMAL, |
311 &extension_info_.icon_image->image_skia()); | 313 &extension_info_.icon_image->image_skia()); |
312 grid_layout->AddView(image_button_); | 314 grid_layout->AddView(image_button_); |
313 } | 315 } |
314 | 316 |
315 // Add zoom label with the new zoom percent. | 317 // Add zoom label with the new zoom percent. |
316 ZoomController* zoom_controller = | 318 ui_zoom::ZoomController* zoom_controller = |
317 ZoomController::FromWebContents(web_contents_); | 319 ui_zoom::ZoomController::FromWebContents(web_contents_); |
318 int zoom_percent = zoom_controller->GetZoomPercent(); | 320 int zoom_percent = zoom_controller->GetZoomPercent(); |
319 label_ = new views::Label( | 321 label_ = new views::Label( |
320 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent)); | 322 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent)); |
321 label_->SetFontList( | 323 label_->SetFontList( |
322 ui::ResourceBundle::GetSharedInstance().GetFontList( | 324 ui::ResourceBundle::GetSharedInstance().GetFontList( |
323 ui::ResourceBundle::MediumFont)); | 325 ui::ResourceBundle::MediumFont)); |
324 grid_layout->AddView(label_); | 326 grid_layout->AddView(label_); |
325 | 327 |
326 // Second row. | 328 // Second row. |
327 grid_layout->AddPaddingRow(0, 8); | 329 grid_layout->AddPaddingRow(0, 8); |
(...skipping 30 matching lines...) Expand all Loading... |
358 void ZoomBubbleView::WindowClosing() { | 360 void ZoomBubbleView::WindowClosing() { |
359 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't | 361 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't |
360 // call this right away). Only set to NULL when it's this bubble. | 362 // call this right away). Only set to NULL when it's this bubble. |
361 if (zoom_bubble_ == this) | 363 if (zoom_bubble_ == this) |
362 zoom_bubble_ = NULL; | 364 zoom_bubble_ = NULL; |
363 } | 365 } |
364 | 366 |
365 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} | 367 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} |
366 | 368 |
367 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} | 369 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} |
OLD | NEW |