| 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/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/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 "components/ui/zoom/page_zoom.h" | 20 #include "components/zoom/page_zoom.h" |
| 21 #include "components/ui/zoom/zoom_controller.h" | 21 #include "components/zoom/zoom_controller.h" |
| 22 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
| 23 #include "extensions/browser/extension_zoom_request_client.h" | 23 #include "extensions/browser/extension_zoom_request_client.h" |
| 24 #include "extensions/common/manifest_handlers/icons_handler.h" | 24 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 25 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/gfx/favicon_size.h" | 28 #include "ui/gfx/favicon_size.h" |
| 29 #include "ui/views/controls/button/image_button.h" | 29 #include "ui/views/controls/button/image_button.h" |
| 30 #include "ui/views/controls/button/md_text_button.h" | 30 #include "ui/views/controls/button/md_text_button.h" |
| 31 #include "ui/views/controls/separator.h" | 31 #include "ui/views/controls/separator.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 44 browser->exclusive_access_manager()->fullscreen_controller()); | 44 browser->exclusive_access_manager()->fullscreen_controller()); |
| 45 | 45 |
| 46 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 46 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
| 47 bool is_fullscreen = browser_view->IsFullscreen(); | 47 bool is_fullscreen = browser_view->IsFullscreen(); |
| 48 bool anchor_to_view = !is_fullscreen || | 48 bool anchor_to_view = !is_fullscreen || |
| 49 browser_view->immersive_mode_controller()->IsRevealed(); | 49 browser_view->immersive_mode_controller()->IsRevealed(); |
| 50 ZoomView* anchor_view = anchor_to_view ? | 50 ZoomView* anchor_view = anchor_to_view ? |
| 51 browser_view->GetLocationBarView()->zoom_view() : NULL; | 51 browser_view->GetLocationBarView()->zoom_view() : NULL; |
| 52 | 52 |
| 53 // Find the extension that initiated the zoom change, if any. | 53 // Find the extension that initiated the zoom change, if any. |
| 54 ui_zoom::ZoomController* zoom_controller = | 54 zoom::ZoomController* zoom_controller = |
| 55 ui_zoom::ZoomController::FromWebContents(web_contents); | 55 zoom::ZoomController::FromWebContents(web_contents); |
| 56 const ui_zoom::ZoomRequestClient* client = zoom_controller->last_client(); | 56 const zoom::ZoomRequestClient* client = zoom_controller->last_client(); |
| 57 | 57 |
| 58 // If the bubble is already showing in this window and the zoom change was not | 58 // If the bubble is already showing in this window and the zoom change was not |
| 59 // initiated by an extension, then the bubble can be reused and only the label | 59 // initiated by an extension, then the bubble can be reused and only the label |
| 60 // text needs to be updated. | 60 // text needs to be updated. |
| 61 if (zoom_bubble_ && zoom_bubble_->GetAnchorView() == anchor_view && !client) { | 61 if (zoom_bubble_ && zoom_bubble_->GetAnchorView() == anchor_view && !client) { |
| 62 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_); | 62 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_); |
| 63 zoom_bubble_->Refresh(); | 63 zoom_bubble_->Refresh(); |
| 64 return; | 64 return; |
| 65 } | 65 } |
| 66 | 66 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 image_button_ = new views::ImageButton(this); | 167 image_button_ = new views::ImageButton(this); |
| 168 image_button_->SetTooltipText( | 168 image_button_->SetTooltipText( |
| 169 l10n_util::GetStringFUTF16(IDS_TOOLTIP_ZOOM_EXTENSION_ICON, | 169 l10n_util::GetStringFUTF16(IDS_TOOLTIP_ZOOM_EXTENSION_ICON, |
| 170 base::UTF8ToUTF16(extension_info_.name))); | 170 base::UTF8ToUTF16(extension_info_.name))); |
| 171 image_button_->SetImage(views::Button::STATE_NORMAL, | 171 image_button_->SetImage(views::Button::STATE_NORMAL, |
| 172 &extension_info_.icon_image->image_skia()); | 172 &extension_info_.icon_image->image_skia()); |
| 173 grid_layout->AddView(image_button_); | 173 grid_layout->AddView(image_button_); |
| 174 } | 174 } |
| 175 | 175 |
| 176 // Add zoom label with the new zoom percent. | 176 // Add zoom label with the new zoom percent. |
| 177 ui_zoom::ZoomController* zoom_controller = | 177 zoom::ZoomController* zoom_controller = |
| 178 ui_zoom::ZoomController::FromWebContents(web_contents_); | 178 zoom::ZoomController::FromWebContents(web_contents_); |
| 179 int zoom_percent = zoom_controller->GetZoomPercent(); | 179 int zoom_percent = zoom_controller->GetZoomPercent(); |
| 180 label_ = new views::Label(l10n_util::GetStringFUTF16( | 180 label_ = new views::Label(l10n_util::GetStringFUTF16( |
| 181 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent))); | 181 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent))); |
| 182 label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | 182 label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 183 ui::ResourceBundle::MediumFont)); | 183 ui::ResourceBundle::MediumFont)); |
| 184 grid_layout->AddView(label_); | 184 grid_layout->AddView(label_); |
| 185 | 185 |
| 186 // Second row. | 186 // Second row. |
| 187 grid_layout->AddPaddingRow(0, 8); | 187 grid_layout->AddPaddingRow(0, 8); |
| 188 columns = grid_layout->AddColumnSet(1); | 188 columns = grid_layout->AddColumnSet(1); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 216 void ZoomBubbleView::ButtonPressed(views::Button* sender, | 216 void ZoomBubbleView::ButtonPressed(views::Button* sender, |
| 217 const ui::Event& event) { | 217 const ui::Event& event) { |
| 218 if (sender == image_button_) { | 218 if (sender == image_button_) { |
| 219 DCHECK(extension_info_.icon_image) << "Invalid button press."; | 219 DCHECK(extension_info_.icon_image) << "Invalid button press."; |
| 220 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 220 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
| 221 chrome::AddSelectedTabWithURL( | 221 chrome::AddSelectedTabWithURL( |
| 222 browser, GURL(base::StringPrintf("chrome://extensions?id=%s", | 222 browser, GURL(base::StringPrintf("chrome://extensions?id=%s", |
| 223 extension_info_.id.c_str())), | 223 extension_info_.id.c_str())), |
| 224 ui::PAGE_TRANSITION_FROM_API); | 224 ui::PAGE_TRANSITION_FROM_API); |
| 225 } else { | 225 } else { |
| 226 ui_zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_RESET); | 226 zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_RESET); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 void ZoomBubbleView::OnImmersiveRevealStarted() { | 230 void ZoomBubbleView::OnImmersiveRevealStarted() { |
| 231 CloseBubble(); | 231 CloseBubble(); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void ZoomBubbleView::OnImmersiveModeControllerDestroyed() { | 234 void ZoomBubbleView::OnImmersiveModeControllerDestroyed() { |
| 235 immersive_mode_controller_ = NULL; | 235 immersive_mode_controller_ = NULL; |
| 236 } | 236 } |
| 237 | 237 |
| 238 void ZoomBubbleView::OnExtensionIconImageChanged( | 238 void ZoomBubbleView::OnExtensionIconImageChanged( |
| 239 extensions::IconImage* /* image */) { | 239 extensions::IconImage* /* image */) { |
| 240 image_button_->SetImage(views::Button::STATE_NORMAL, | 240 image_button_->SetImage(views::Button::STATE_NORMAL, |
| 241 &extension_info_.icon_image->image_skia()); | 241 &extension_info_.icon_image->image_skia()); |
| 242 image_button_->SchedulePaint(); | 242 image_button_->SchedulePaint(); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void ZoomBubbleView::Refresh() { | 245 void ZoomBubbleView::Refresh() { |
| 246 ui_zoom::ZoomController* zoom_controller = | 246 zoom::ZoomController* zoom_controller = |
| 247 ui_zoom::ZoomController::FromWebContents(web_contents_); | 247 zoom::ZoomController::FromWebContents(web_contents_); |
| 248 int zoom_percent = zoom_controller->GetZoomPercent(); | 248 int zoom_percent = zoom_controller->GetZoomPercent(); |
| 249 label_->SetText(l10n_util::GetStringFUTF16( | 249 label_->SetText(l10n_util::GetStringFUTF16( |
| 250 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent))); | 250 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent))); |
| 251 StartTimerIfNecessary(); | 251 StartTimerIfNecessary(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void ZoomBubbleView::SetExtensionInfo(const extensions::Extension* extension) { | 254 void ZoomBubbleView::SetExtensionInfo(const extensions::Extension* extension) { |
| 255 DCHECK(extension); | 255 DCHECK(extension); |
| 256 extension_info_.id = extension->id(); | 256 extension_info_.id = extension->id(); |
| 257 extension_info_.name = extension->name(); | 257 extension_info_.name = extension->name(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 | 313 |
| 314 void ZoomBubbleView::StopTimer() { | 314 void ZoomBubbleView::StopTimer() { |
| 315 timer_.Stop(); | 315 timer_.Stop(); |
| 316 } | 316 } |
| 317 | 317 |
| 318 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} | 318 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} |
| 319 | 319 |
| 320 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} | 320 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} |
| OLD | NEW |