Chromium Code Reviews| 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/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
| 8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/platform_util.h" | |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
| 13 #include "chrome/browser/ui/browser_tabstrip.h" | 14 #include "chrome/browser/ui/browser_tabstrip.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.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/common/extensions/api/extension_action/action_info.h" | 18 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 19 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| 20 #include "chrome/grit/theme_resources.h" | 20 #include "chrome/grit/theme_resources.h" |
| 21 #include "components/zoom/page_zoom.h" | 21 #include "components/zoom/page_zoom.h" |
| 22 #include "components/zoom/zoom_controller.h" | 22 #include "components/zoom/zoom_controller.h" |
| 23 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 24 #include "extensions/browser/extension_zoom_request_client.h" | 24 #include "extensions/browser/extension_zoom_request_client.h" |
| 25 #include "extensions/common/manifest_handlers/icons_handler.h" | 25 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/base/material_design/material_design_controller.h" | 27 #include "ui/base/material_design/material_design_controller.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "ui/base/ui_features.h" | |
| 29 #include "ui/gfx/favicon_size.h" | 30 #include "ui/gfx/favicon_size.h" |
| 30 #include "ui/views/controls/button/image_button.h" | 31 #include "ui/views/controls/button/image_button.h" |
| 31 #include "ui/views/controls/button/md_text_button.h" | 32 #include "ui/views/controls/button/md_text_button.h" |
| 32 #include "ui/views/controls/separator.h" | 33 #include "ui/views/controls/separator.h" |
| 33 #include "ui/views/layout/grid_layout.h" | 34 #include "ui/views/layout/grid_layout.h" |
| 34 #include "ui/views/layout/layout_constants.h" | 35 #include "ui/views/layout/layout_constants.h" |
| 35 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
| 36 | 37 |
| 38 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
| 39 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 40 #endif | |
| 41 | |
| 37 // static | 42 // static |
| 38 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = nullptr; | 43 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = nullptr; |
| 39 | 44 |
| 40 // static | 45 // static |
| 41 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents, | 46 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents, |
| 47 const gfx::Point& anchor_point, | |
| 42 DisplayReason reason) { | 48 DisplayReason reason) { |
| 43 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 49 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 44 DCHECK(browser && browser->window() && | 50 DCHECK(browser && browser->window() && |
| 45 browser->exclusive_access_manager()->fullscreen_controller()); | 51 browser->exclusive_access_manager()->fullscreen_controller()); |
| 46 | 52 |
| 53 views::View* anchor_view = nullptr; | |
| 54 ImmersiveModeController* immersive_mode_controller = nullptr; | |
| 55 bool is_fullscreen = browser->window()->IsFullscreen(); | |
| 56 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
| 47 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 57 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
| 48 bool is_fullscreen = browser_view->IsFullscreen(); | |
| 49 views::View* anchor_view = nullptr; | |
| 50 if (!is_fullscreen || | 58 if (!is_fullscreen || |
| 51 browser_view->immersive_mode_controller()->IsRevealed()) { | 59 browser_view->immersive_mode_controller()->IsRevealed()) { |
| 52 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) | 60 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) |
| 53 anchor_view = browser_view->GetLocationBarView(); | 61 anchor_view = browser_view->GetLocationBarView(); |
| 54 else | 62 else |
| 55 anchor_view = browser_view->GetLocationBarView()->zoom_view(); | 63 anchor_view = browser_view->GetLocationBarView()->zoom_view(); |
| 56 } | 64 } |
| 65 immersive_mode_controller = browser_view->immersive_mode_controller(); | |
| 66 #endif | |
| 57 | 67 |
| 58 // Find the extension that initiated the zoom change, if any. | 68 // Find the extension that initiated the zoom change, if any. |
| 59 zoom::ZoomController* zoom_controller = | 69 zoom::ZoomController* zoom_controller = |
| 60 zoom::ZoomController::FromWebContents(web_contents); | 70 zoom::ZoomController::FromWebContents(web_contents); |
| 61 const zoom::ZoomRequestClient* client = zoom_controller->last_client(); | 71 const zoom::ZoomRequestClient* client = zoom_controller->last_client(); |
| 62 | 72 |
| 63 // If the bubble is already showing in this window and the zoom change was not | 73 // If the bubble is already showing in this window and the zoom change was not |
| 64 // initiated by an extension, then the bubble can be reused and only the label | 74 // initiated by an extension, then the bubble can be reused and only the label |
| 65 // text needs to be updated. | 75 // text needs to be updated. |
| 66 if (zoom_bubble_ && zoom_bubble_->GetAnchorView() == anchor_view && !client) { | 76 if (zoom_bubble_ && zoom_bubble_->GetAnchorView() == anchor_view && !client) { |
| 67 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_); | 77 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_); |
| 68 zoom_bubble_->Refresh(); | 78 zoom_bubble_->Refresh(); |
| 69 return; | 79 return; |
| 70 } | 80 } |
| 71 | 81 |
| 72 // If the bubble is already showing but in a different tab, the current | 82 // If the bubble is already showing but in a different tab, the current |
| 73 // bubble must be closed and a new one created. | 83 // bubble must be closed and a new one created. |
| 74 CloseCurrentBubble(); | 84 CloseCurrentBubble(); |
| 75 | 85 |
| 76 zoom_bubble_ = new ZoomBubbleView(anchor_view, web_contents, reason, | 86 zoom_bubble_ = new ZoomBubbleView(anchor_view, anchor_point, web_contents, |
| 77 browser_view->immersive_mode_controller()); | 87 reason, immersive_mode_controller); |
| 78 | 88 |
| 79 // If the zoom change was initiated by an extension, capture the relevent | 89 // If the zoom change was initiated by an extension, capture the relevent |
| 80 // information from it. | 90 // information from it. |
| 81 if (client) { | 91 if (client) { |
| 82 zoom_bubble_->SetExtensionInfo( | 92 zoom_bubble_->SetExtensionInfo( |
| 83 static_cast<const extensions::ExtensionZoomRequestClient*>(client) | 93 static_cast<const extensions::ExtensionZoomRequestClient*>(client) |
| 84 ->extension()); | 94 ->extension()); |
| 85 } | 95 } |
| 86 | 96 |
| 97 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
| 87 // If we do not have an anchor view, parent the bubble to the content area. | 98 // If we do not have an anchor view, parent the bubble to the content area. |
| 88 if (!anchor_view) | 99 if (!anchor_view) |
| 89 zoom_bubble_->set_parent_window(web_contents->GetNativeView()); | 100 zoom_bubble_->set_parent_window(web_contents->GetNativeView()); |
| 90 | 101 |
| 91 views::Widget* zoom_bubble_widget = | 102 views::Widget* zoom_bubble_widget = |
| 92 views::BubbleDialogDelegateView::CreateBubble(zoom_bubble_); | 103 views::BubbleDialogDelegateView::CreateBubble(zoom_bubble_); |
| 93 if (anchor_view) { | 104 if (anchor_view) { |
| 94 zoom_bubble_widget->AddObserver( | 105 zoom_bubble_widget->AddObserver( |
| 95 browser_view->GetLocationBarView()->zoom_view()); | 106 browser_view->GetLocationBarView()->zoom_view()); |
| 96 } | 107 } |
| 108 #else | |
| 109 gfx::NativeView parent = | |
| 110 platform_util::GetViewForWindow(browser->window()->GetNativeWindow()); | |
| 111 DCHECK(parent); | |
| 112 zoom_bubble_->set_arrow(views::BubbleBorder::TOP_RIGHT); | |
| 113 zoom_bubble_->set_parent_window(parent); | |
| 114 views::BubbleDialogDelegateView::CreateBubble(zoom_bubble_); | |
| 115 #endif | |
| 97 | 116 |
| 98 // Adjust for fullscreen after creation as it relies on the content size. | 117 // Adjust for fullscreen after creation as it relies on the content size. |
| 99 if (is_fullscreen) | 118 if (is_fullscreen) |
| 100 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); | 119 zoom_bubble_->AdjustForFullscreen(browser->window()->GetBounds()); |
| 101 | 120 |
| 102 zoom_bubble_->ShowForReason(reason); | 121 zoom_bubble_->ShowForReason(reason); |
| 103 } | 122 } |
| 104 | 123 |
| 105 // static | 124 // static |
| 106 void ZoomBubbleView::CloseCurrentBubble() { | 125 void ZoomBubbleView::CloseCurrentBubble() { |
| 107 if (zoom_bubble_) | 126 if (zoom_bubble_) |
| 108 zoom_bubble_->CloseBubble(); | 127 zoom_bubble_->CloseBubble(); |
| 109 } | 128 } |
| 110 | 129 |
| 111 // static | 130 // static |
| 112 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() { | 131 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() { |
| 113 return zoom_bubble_; | 132 return zoom_bubble_; |
| 114 } | 133 } |
| 115 | 134 |
| 135 void ZoomBubbleView::Refresh() { | |
| 136 zoom::ZoomController* zoom_controller = | |
| 137 zoom::ZoomController::FromWebContents(web_contents_); | |
| 138 int zoom_percent = zoom_controller->GetZoomPercent(); | |
| 139 label_->SetText(l10n_util::GetStringFUTF16( | |
| 140 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent))); | |
| 141 StartTimerIfNecessary(); | |
| 142 } | |
| 143 | |
| 116 ZoomBubbleView::ZoomBubbleView( | 144 ZoomBubbleView::ZoomBubbleView( |
| 117 views::View* anchor_view, | 145 views::View* anchor_view, |
| 146 const gfx::Point& anchor_point, | |
| 118 content::WebContents* web_contents, | 147 content::WebContents* web_contents, |
| 119 DisplayReason reason, | 148 DisplayReason reason, |
| 120 ImmersiveModeController* immersive_mode_controller) | 149 ImmersiveModeController* immersive_mode_controller) |
| 121 : LocationBarBubbleDelegateView(anchor_view, web_contents), | 150 : LocationBarBubbleDelegateView(anchor_view, anchor_point, web_contents), |
| 122 image_button_(nullptr), | 151 image_button_(nullptr), |
| 123 label_(nullptr), | 152 label_(nullptr), |
| 124 web_contents_(web_contents), | 153 web_contents_(web_contents), |
| 125 auto_close_(reason == AUTOMATIC), | 154 auto_close_(reason == AUTOMATIC), |
| 126 immersive_mode_controller_(immersive_mode_controller) { | 155 immersive_mode_controller_(immersive_mode_controller) { |
| 127 set_notify_enter_exit_on_child(true); | 156 set_notify_enter_exit_on_child(true); |
| 128 immersive_mode_controller_->AddObserver(this); | 157 if (immersive_mode_controller_) |
| 158 immersive_mode_controller_->AddObserver(this); | |
| 129 UseCompactMargins(); | 159 UseCompactMargins(); |
| 130 } | 160 } |
| 131 | 161 |
| 132 ZoomBubbleView::~ZoomBubbleView() { | 162 ZoomBubbleView::~ZoomBubbleView() { |
| 133 if (immersive_mode_controller_) | 163 if (immersive_mode_controller_) |
| 134 immersive_mode_controller_->RemoveObserver(this); | 164 immersive_mode_controller_->RemoveObserver(this); |
| 135 } | 165 } |
| 136 | 166 |
| 137 void ZoomBubbleView::OnGestureEvent(ui::GestureEvent* event) { | 167 void ZoomBubbleView::OnGestureEvent(ui::GestureEvent* event) { |
| 138 if (!zoom_bubble_ || !zoom_bubble_->auto_close_ || | 168 if (!zoom_bubble_ || !zoom_bubble_->auto_close_ || |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 &extension_info_.icon_image->image_skia()); | 209 &extension_info_.icon_image->image_skia()); |
| 180 grid_layout->AddView(image_button_); | 210 grid_layout->AddView(image_button_); |
| 181 } | 211 } |
| 182 | 212 |
| 183 // Add zoom label with the new zoom percent. | 213 // Add zoom label with the new zoom percent. |
| 184 zoom::ZoomController* zoom_controller = | 214 zoom::ZoomController* zoom_controller = |
| 185 zoom::ZoomController::FromWebContents(web_contents_); | 215 zoom::ZoomController::FromWebContents(web_contents_); |
| 186 int zoom_percent = zoom_controller->GetZoomPercent(); | 216 int zoom_percent = zoom_controller->GetZoomPercent(); |
| 187 label_ = new views::Label(l10n_util::GetStringFUTF16( | 217 label_ = new views::Label(l10n_util::GetStringFUTF16( |
| 188 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent))); | 218 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent))); |
| 189 label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | 219 label_->SetFontList(GetTitleFontList()); |
|
msw
2017/04/24 18:53:39
aside: when updating the bubble appearance in a fo
varkha
2017/04/26 04:52:59
Not sure. The new mocks still show this not above
| |
| 190 ui::ResourceBundle::MediumFont)); | |
| 191 grid_layout->AddView(label_); | 220 grid_layout->AddView(label_); |
| 192 | 221 |
| 193 // Second row. | 222 // Second row. |
| 194 grid_layout->AddPaddingRow(0, 8); | 223 grid_layout->AddPaddingRow(0, 8); |
| 195 columns = grid_layout->AddColumnSet(1); | 224 columns = grid_layout->AddColumnSet(1); |
| 196 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 225 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 197 views::GridLayout::USE_PREF, 0, 0); | 226 views::GridLayout::USE_PREF, 0, 0); |
| 198 grid_layout->StartRow(0, 1); | 227 grid_layout->StartRow(0, 1); |
| 199 | 228 |
| 200 // Add "Reset to Default" button. | 229 // Add "Reset to Default" button. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 immersive_mode_controller_ = nullptr; | 271 immersive_mode_controller_ = nullptr; |
| 243 } | 272 } |
| 244 | 273 |
| 245 void ZoomBubbleView::OnExtensionIconImageChanged( | 274 void ZoomBubbleView::OnExtensionIconImageChanged( |
| 246 extensions::IconImage* /* image */) { | 275 extensions::IconImage* /* image */) { |
| 247 image_button_->SetImage(views::Button::STATE_NORMAL, | 276 image_button_->SetImage(views::Button::STATE_NORMAL, |
| 248 &extension_info_.icon_image->image_skia()); | 277 &extension_info_.icon_image->image_skia()); |
| 249 image_button_->SchedulePaint(); | 278 image_button_->SchedulePaint(); |
| 250 } | 279 } |
| 251 | 280 |
| 252 void ZoomBubbleView::Refresh() { | |
| 253 zoom::ZoomController* zoom_controller = | |
| 254 zoom::ZoomController::FromWebContents(web_contents_); | |
| 255 int zoom_percent = zoom_controller->GetZoomPercent(); | |
| 256 label_->SetText(l10n_util::GetStringFUTF16( | |
| 257 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent))); | |
| 258 StartTimerIfNecessary(); | |
| 259 } | |
| 260 | |
| 261 void ZoomBubbleView::SetExtensionInfo(const extensions::Extension* extension) { | 281 void ZoomBubbleView::SetExtensionInfo(const extensions::Extension* extension) { |
| 262 DCHECK(extension); | 282 DCHECK(extension); |
| 263 extension_info_.id = extension->id(); | 283 extension_info_.id = extension->id(); |
| 264 extension_info_.name = extension->name(); | 284 extension_info_.name = extension->name(); |
| 265 | 285 |
| 266 ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 286 ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 267 const gfx::ImageSkia& default_extension_icon_image = | 287 const gfx::ImageSkia& default_extension_icon_image = |
| 268 *rb.GetImageSkiaNamed(IDR_EXTENSIONS_FAVICON); | 288 *rb.GetImageSkiaNamed(IDR_EXTENSIONS_FAVICON); |
| 269 int icon_size = gfx::kFaviconSize; | 289 int icon_size = gfx::kFaviconSize; |
| 270 | 290 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 } | 338 } |
| 319 } | 339 } |
| 320 | 340 |
| 321 void ZoomBubbleView::StopTimer() { | 341 void ZoomBubbleView::StopTimer() { |
| 322 timer_.Stop(); | 342 timer_.Stop(); |
| 323 } | 343 } |
| 324 | 344 |
| 325 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} | 345 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} |
| 326 | 346 |
| 327 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} | 347 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} |
| OLD | NEW |