Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: chrome/browser/ui/views/location_bar/zoom_bubble_view.cc

Issue 769593003: Move ZoomObserver, ZoomController and ZoomEventManager to components/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac build fix #4. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
21 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
21 #include "extensions/browser/ui/zoom/zoom_controller.h"
22 #include "extensions/common/manifest_handlers/icons_handler.h" 22 #include "extensions/common/manifest_handlers/icons_handler.h"
23 #include "grit/theme_resources.h" 23 #include "grit/theme_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/gfx/favicon_size.h" 26 #include "ui/gfx/favicon_size.h"
27 #include "ui/views/controls/button/image_button.h" 27 #include "ui/views/controls/button/image_button.h"
28 #include "ui/views/controls/button/label_button.h" 28 #include "ui/views/controls/button/label_button.h"
29 #include "ui/views/controls/separator.h" 29 #include "ui/views/controls/separator.h"
30 #include "ui/views/layout/grid_layout.h" 30 #include "ui/views/layout/grid_layout.h"
31 #include "ui/views/layout/layout_constants.h" 31 #include "ui/views/layout/layout_constants.h"
(...skipping 20 matching lines...) Expand all
52 DCHECK(browser && browser->window() && browser->fullscreen_controller()); 52 DCHECK(browser && browser->window() && browser->fullscreen_controller());
53 53
54 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 54 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
55 bool is_fullscreen = browser_view->IsFullscreen(); 55 bool is_fullscreen = browser_view->IsFullscreen();
56 bool anchor_to_view = !is_fullscreen || 56 bool anchor_to_view = !is_fullscreen ||
57 browser_view->immersive_mode_controller()->IsRevealed(); 57 browser_view->immersive_mode_controller()->IsRevealed();
58 views::View* anchor_view = anchor_to_view ? 58 views::View* anchor_view = anchor_to_view ?
59 browser_view->GetLocationBarView()->zoom_view() : NULL; 59 browser_view->GetLocationBarView()->zoom_view() : NULL;
60 60
61 // Find the extension that initiated the zoom change, if any. 61 // Find the extension that initiated the zoom change, if any.
62 ZoomController* zoom_controller = 62 extensions::ZoomController* zoom_controller =
63 ZoomController::FromWebContents(web_contents); 63 extensions::ZoomController::FromWebContents(web_contents);
64 const extensions::Extension* extension = zoom_controller->last_extension(); 64 const extensions::Extension* extension = zoom_controller->last_extension();
65 65
66 // If the bubble is already showing in this window and the zoom change was not 66 // 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 67 // initiated by an extension, then the bubble can be reused and only the label
68 // text needs to be updated. 68 // text needs to be updated.
69 if (zoom_bubble_ && 69 if (zoom_bubble_ &&
70 zoom_bubble_->GetAnchorView() == anchor_view && 70 zoom_bubble_->GetAnchorView() == anchor_view &&
71 !extension) { 71 !extension) {
72 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_); 72 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_);
73 zoom_bubble_->Refresh(); 73 zoom_bubble_->Refresh();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 159
160 // TODO(dbeam): should RTL logic be done in views::BubbleDelegateView? 160 // TODO(dbeam): should RTL logic be done in views::BubbleDelegateView?
161 const size_t bubble_half_width = width() / 2; 161 const size_t bubble_half_width = width() / 2;
162 const int x_pos = base::i18n::IsRTL() ? 162 const int x_pos = base::i18n::IsRTL() ?
163 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : 163 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd :
164 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; 164 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd;
165 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); 165 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0));
166 } 166 }
167 167
168 void ZoomBubbleView::Refresh() { 168 void ZoomBubbleView::Refresh() {
169 ZoomController* zoom_controller = 169 extensions::ZoomController* zoom_controller =
170 ZoomController::FromWebContents(web_contents_); 170 extensions::ZoomController::FromWebContents(web_contents_);
171 int zoom_percent = zoom_controller->GetZoomPercent(); 171 int zoom_percent = zoom_controller->GetZoomPercent();
172 label_->SetText( 172 label_->SetText(
173 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent)); 173 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent));
174 StartTimerIfNecessary(); 174 StartTimerIfNecessary();
175 } 175 }
176 176
177 void ZoomBubbleView::Close() { 177 void ZoomBubbleView::Close() {
178 // Widget's Close() is async, but we don't want to use zoom_bubble_ after 178 // Widget's Close() is async, but we don't want to use zoom_bubble_ after
179 // this. Additionally web_contents_ may have been destroyed. 179 // this. Additionally web_contents_ may have been destroyed.
180 zoom_bubble_ = NULL; 180 zoom_bubble_ = NULL;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 image_button_ = new views::ImageButton(this); 306 image_button_ = new views::ImageButton(this);
307 image_button_->SetTooltipText(l10n_util::GetStringFUTF16( 307 image_button_->SetTooltipText(l10n_util::GetStringFUTF16(
308 IDS_TOOLTIP_ZOOM_EXTENSION_ICON, 308 IDS_TOOLTIP_ZOOM_EXTENSION_ICON,
309 base::UTF8ToUTF16(extension_info_.name))); 309 base::UTF8ToUTF16(extension_info_.name)));
310 image_button_->SetImage(views::Button::STATE_NORMAL, 310 image_button_->SetImage(views::Button::STATE_NORMAL,
311 &extension_info_.icon_image->image_skia()); 311 &extension_info_.icon_image->image_skia());
312 grid_layout->AddView(image_button_); 312 grid_layout->AddView(image_button_);
313 } 313 }
314 314
315 // Add zoom label with the new zoom percent. 315 // Add zoom label with the new zoom percent.
316 ZoomController* zoom_controller = 316 extensions::ZoomController* zoom_controller =
317 ZoomController::FromWebContents(web_contents_); 317 extensions::ZoomController::FromWebContents(web_contents_);
318 int zoom_percent = zoom_controller->GetZoomPercent(); 318 int zoom_percent = zoom_controller->GetZoomPercent();
319 label_ = new views::Label( 319 label_ = new views::Label(
320 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent)); 320 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent));
321 label_->SetFontList( 321 label_->SetFontList(
322 ui::ResourceBundle::GetSharedInstance().GetFontList( 322 ui::ResourceBundle::GetSharedInstance().GetFontList(
323 ui::ResourceBundle::MediumFont)); 323 ui::ResourceBundle::MediumFont));
324 grid_layout->AddView(label_); 324 grid_layout->AddView(label_);
325 325
326 // Second row. 326 // Second row.
327 grid_layout->AddPaddingRow(0, 8); 327 grid_layout->AddPaddingRow(0, 8);
(...skipping 30 matching lines...) Expand all
358 void ZoomBubbleView::WindowClosing() { 358 void ZoomBubbleView::WindowClosing() {
359 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't 359 // |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. 360 // call this right away). Only set to NULL when it's this bubble.
361 if (zoom_bubble_ == this) 361 if (zoom_bubble_ == this)
362 zoom_bubble_ = NULL; 362 zoom_bubble_ = NULL;
363 } 363 }
364 364
365 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} 365 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {}
366 366
367 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} 367 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698