| 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 components::ZoomController* zoom_controller = |
| 63 ZoomController::FromWebContents(web_contents); | 64 components::ZoomController::FromWebContents(web_contents); |
| 64 const extensions::Extension* extension = zoom_controller->last_extension(); | 65 const components::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_ && |
| 70 zoom_bubble_->GetAnchorView() == anchor_view && | 71 zoom_bubble_->GetAnchorView() == anchor_view && |
| 71 !extension) { | 72 !client) { |
| 72 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_); | 73 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_); |
| 73 zoom_bubble_->Refresh(); | 74 zoom_bubble_->Refresh(); |
| 74 return; | 75 return; |
| 75 } | 76 } |
| 76 | 77 |
| 77 // If the bubble is already showing but in a different tab, the current | 78 // If the bubble is already showing but in a different tab, the current |
| 78 // bubble must be closed and a new one created. | 79 // bubble must be closed and a new one created. |
| 79 CloseBubble(); | 80 CloseBubble(); |
| 80 | 81 |
| 81 zoom_bubble_ = new ZoomBubbleView(anchor_view, | 82 zoom_bubble_ = new ZoomBubbleView(anchor_view, |
| 82 web_contents, | 83 web_contents, |
| 83 auto_close, | 84 auto_close, |
| 84 browser_view->immersive_mode_controller(), | 85 browser_view->immersive_mode_controller(), |
| 85 browser->fullscreen_controller()); | 86 browser->fullscreen_controller()); |
| 86 | 87 |
| 87 // If the zoom change was initiated by an extension, capture the relevent | 88 // If the zoom change was initiated by an extension, capture the relevent |
| 88 // information from it. | 89 // information from it. |
| 89 if (extension) | 90 if (client) { |
| 90 zoom_bubble_->SetExtensionInfo(extension); | 91 zoom_bubble_->SetExtensionInfo( |
| 92 static_cast<const extensions::ExtensionZoomRequestClient*>(client) |
| 93 ->extension()); |
| 94 } |
| 91 | 95 |
| 92 // If we do not have an anchor view, parent the bubble to the content area. | 96 // If we do not have an anchor view, parent the bubble to the content area. |
| 93 if (!anchor_to_view) | 97 if (!anchor_to_view) |
| 94 zoom_bubble_->set_parent_window(web_contents->GetTopLevelNativeWindow()); | 98 zoom_bubble_->set_parent_window(web_contents->GetTopLevelNativeWindow()); |
| 95 | 99 |
| 96 views::BubbleDelegateView::CreateBubble(zoom_bubble_); | 100 views::BubbleDelegateView::CreateBubble(zoom_bubble_); |
| 97 | 101 |
| 98 // Adjust for fullscreen after creation as it relies on the content size. | 102 // Adjust for fullscreen after creation as it relies on the content size. |
| 99 if (is_fullscreen) | 103 if (is_fullscreen) |
| 100 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); | 104 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 163 |
| 160 // TODO(dbeam): should RTL logic be done in views::BubbleDelegateView? | 164 // TODO(dbeam): should RTL logic be done in views::BubbleDelegateView? |
| 161 const size_t bubble_half_width = width() / 2; | 165 const size_t bubble_half_width = width() / 2; |
| 162 const int x_pos = base::i18n::IsRTL() ? | 166 const int x_pos = base::i18n::IsRTL() ? |
| 163 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : | 167 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : |
| 164 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; | 168 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; |
| 165 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); | 169 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); |
| 166 } | 170 } |
| 167 | 171 |
| 168 void ZoomBubbleView::Refresh() { | 172 void ZoomBubbleView::Refresh() { |
| 169 ZoomController* zoom_controller = | 173 components::ZoomController* zoom_controller = |
| 170 ZoomController::FromWebContents(web_contents_); | 174 components::ZoomController::FromWebContents(web_contents_); |
| 171 int zoom_percent = zoom_controller->GetZoomPercent(); | 175 int zoom_percent = zoom_controller->GetZoomPercent(); |
| 172 label_->SetText( | 176 label_->SetText( |
| 173 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent)); | 177 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent)); |
| 174 StartTimerIfNecessary(); | 178 StartTimerIfNecessary(); |
| 175 } | 179 } |
| 176 | 180 |
| 177 void ZoomBubbleView::Close() { | 181 void ZoomBubbleView::Close() { |
| 178 // Widget's Close() is async, but we don't want to use zoom_bubble_ after | 182 // Widget's Close() is async, but we don't want to use zoom_bubble_ after |
| 179 // this. Additionally web_contents_ may have been destroyed. | 183 // this. Additionally web_contents_ may have been destroyed. |
| 180 zoom_bubble_ = NULL; | 184 zoom_bubble_ = NULL; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 image_button_ = new views::ImageButton(this); | 310 image_button_ = new views::ImageButton(this); |
| 307 image_button_->SetTooltipText(l10n_util::GetStringFUTF16( | 311 image_button_->SetTooltipText(l10n_util::GetStringFUTF16( |
| 308 IDS_TOOLTIP_ZOOM_EXTENSION_ICON, | 312 IDS_TOOLTIP_ZOOM_EXTENSION_ICON, |
| 309 base::UTF8ToUTF16(extension_info_.name))); | 313 base::UTF8ToUTF16(extension_info_.name))); |
| 310 image_button_->SetImage(views::Button::STATE_NORMAL, | 314 image_button_->SetImage(views::Button::STATE_NORMAL, |
| 311 &extension_info_.icon_image->image_skia()); | 315 &extension_info_.icon_image->image_skia()); |
| 312 grid_layout->AddView(image_button_); | 316 grid_layout->AddView(image_button_); |
| 313 } | 317 } |
| 314 | 318 |
| 315 // Add zoom label with the new zoom percent. | 319 // Add zoom label with the new zoom percent. |
| 316 ZoomController* zoom_controller = | 320 components::ZoomController* zoom_controller = |
| 317 ZoomController::FromWebContents(web_contents_); | 321 components::ZoomController::FromWebContents(web_contents_); |
| 318 int zoom_percent = zoom_controller->GetZoomPercent(); | 322 int zoom_percent = zoom_controller->GetZoomPercent(); |
| 319 label_ = new views::Label( | 323 label_ = new views::Label( |
| 320 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent)); | 324 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent)); |
| 321 label_->SetFontList( | 325 label_->SetFontList( |
| 322 ui::ResourceBundle::GetSharedInstance().GetFontList( | 326 ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 323 ui::ResourceBundle::MediumFont)); | 327 ui::ResourceBundle::MediumFont)); |
| 324 grid_layout->AddView(label_); | 328 grid_layout->AddView(label_); |
| 325 | 329 |
| 326 // Second row. | 330 // Second row. |
| 327 grid_layout->AddPaddingRow(0, 8); | 331 grid_layout->AddPaddingRow(0, 8); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 358 void ZoomBubbleView::WindowClosing() { | 362 void ZoomBubbleView::WindowClosing() { |
| 359 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't | 363 // |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. | 364 // call this right away). Only set to NULL when it's this bubble. |
| 361 if (zoom_bubble_ == this) | 365 if (zoom_bubble_ == this) |
| 362 zoom_bubble_ = NULL; | 366 zoom_bubble_ = NULL; |
| 363 } | 367 } |
| 364 | 368 |
| 365 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} | 369 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} |
| 366 | 370 |
| 367 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} | 371 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} |
| OLD | NEW |