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

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

Issue 10736028: Refactor browser window zoom handling and enable zoom icon on all platforms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 months 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 | Annotate | Revision Log
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_view.h" 5 #include "chrome/browser/ui/views/location_bar/zoom_view.h"
6 6
7 #include "chrome/browser/ui/views/browser_dialogs.h" 7 #include "chrome/browser/ui/views/browser_dialogs.h"
8 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" 8 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
9 #include "chrome/browser/ui/view_ids.h" 9 #include "chrome/browser/ui/view_ids.h"
10 #include "chrome/browser/ui/zoom/zoom_controller.h"
10 #include "grit/generated_resources.h" 11 #include "grit/generated_resources.h"
11 #include "grit/theme_resources.h" 12 #include "grit/theme_resources.h"
12 #include "ui/base/accessibility/accessible_view_state.h" 13 #include "ui/base/accessibility/accessible_view_state.h"
13 #include "ui/base/event.h" 14 #include "ui/base/event.h"
14 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/size.h" 17 #include "ui/gfx/size.h"
17 18
18 ZoomView::ZoomView(ToolbarModel* toolbar_model, 19 ZoomView::ZoomView(ToolbarModel* toolbar_model,
19 LocationBarView::Delegate* location_bar_delegate) 20 LocationBarView::Delegate* location_bar_delegate)
20 : toolbar_model_(toolbar_model), 21 : toolbar_model_(toolbar_model),
21 location_bar_delegate_(location_bar_delegate), 22 location_bar_delegate_(location_bar_delegate) {
22 zoom_icon_state_(ZoomController::NONE),
23 zoom_percent_(100) {
24 set_accessibility_focusable(true); 23 set_accessibility_focusable(true);
24 Update(NULL);
25 } 25 }
26 26
27 ZoomView::~ZoomView() { 27 ZoomView::~ZoomView() {
28 } 28 }
29 29
30 void ZoomView::SetZoomIconState(ZoomController::ZoomIconState zoom_icon_state) { 30 void ZoomView::Update(ZoomController* zoom_controller) {
31 if (zoom_icon_state == zoom_icon_state_) 31 if (!zoom_controller || zoom_controller->IsAtDefaultZoom() ||
32 return; 32 toolbar_model_->input_in_progress()) {
33
34 zoom_icon_state_ = zoom_icon_state;
35 Update();
36 }
37
38 void ZoomView::SetZoomIconTooltipPercent(int zoom_percent) {
39 if (zoom_percent == zoom_percent_)
40 return;
41
42 zoom_percent_ = zoom_percent;
43 Update();
44 }
45
46 void ZoomView::Update() {
47 if (toolbar_model_->input_in_progress() ||
48 zoom_icon_state_ == ZoomController::NONE) {
49 SetVisible(false); 33 SetVisible(false);
50 ZoomBubbleView::CloseBubble(); 34 ZoomBubbleView::CloseBubble();
51 } else { 35 return;
52 SetVisible(true);
53 SetTooltipText(
54 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent_));
55 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
56 zoom_icon_state_ == ZoomController::ZOOM_PLUS_ICON ?
57 IDR_ZOOM_PLUS : IDR_ZOOM_MINUS));
58 } 36 }
37
38 SetTooltipText(l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM,
39 zoom_controller->zoom_percent()));
40 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
41 zoom_controller->GetResourceForZoomLevel()));
42 SetVisible(true);
59 } 43 }
60 44
61 void ZoomView::GetAccessibleState(ui::AccessibleViewState* state) { 45 void ZoomView::GetAccessibleState(ui::AccessibleViewState* state) {
62 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM); 46 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM);
63 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; 47 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
64 } 48 }
65 49
66 bool ZoomView::GetTooltipText(const gfx::Point& p, string16* tooltip) const { 50 bool ZoomView::GetTooltipText(const gfx::Point& p, string16* tooltip) const {
67 // Don't show tooltip if the zoom bubble is displayed. 51 // Don't show tooltip if the zoom bubble is displayed.
68 return !ZoomBubbleView::IsShowing() && ImageView::GetTooltipText(p, tooltip); 52 return !ZoomBubbleView::IsShowing() && ImageView::GetTooltipText(p, tooltip);
(...skipping 13 matching lines...) Expand all
82 66
83 bool ZoomView::OnKeyPressed(const ui::KeyEvent& event) { 67 bool ZoomView::OnKeyPressed(const ui::KeyEvent& event) {
84 if (event.key_code() != ui::VKEY_SPACE && 68 if (event.key_code() != ui::VKEY_SPACE &&
85 event.key_code() != ui::VKEY_RETURN) 69 event.key_code() != ui::VKEY_RETURN)
86 return false; 70 return false;
87 71
88 ZoomBubbleView::ShowBubble( 72 ZoomBubbleView::ShowBubble(
89 this, location_bar_delegate_->GetTabContents(), false); 73 this, location_bar_delegate_->GetTabContents(), false);
90 return true; 74 return true;
91 } 75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698