OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/views/location_bar/zoom_view.h" | |
6 | |
7 #include "chrome/browser/ui/views/browser_dialogs.h" | |
8 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | |
9 #include "chrome/browser/ui/view_ids.h" | |
10 #include "grit/generated_resources.h" | |
11 #include "grit/theme_resources_standard.h" | |
12 #include "ui/base/accessibility/accessible_view_state.h" | |
13 #include "ui/base/l10n/l10n_util.h" | |
14 #include "ui/base/resource/resource_bundle.h" | |
15 #include "ui/gfx/size.h" | |
16 | |
17 namespace { | |
18 | |
19 // The size (in pixels) of a side of the icon. | |
20 const int kIconSideLength = 19; | |
21 | |
22 } | |
23 | |
24 ZoomView::ZoomView(ToolbarModel* toolbar_model) | |
25 : toolbar_model_(toolbar_model), | |
26 zoom_icon_state_(ZoomController::NONE), | |
27 zoom_percent_(100) { | |
28 set_accessibility_focusable(true); | |
29 | |
30 gfx::Size size(kIconSideLength, kIconSideLength); | |
31 SetImageSize(size); | |
Peter Kasting
2012/06/26 23:23:39
Nit: Is it possible to omit this, calculate it dyn
Kyle Horimoto
2012/06/30 00:22:50
This cannot be ommitted because the image size mus
Peter Kasting
2012/07/02 19:21:27
I don't think this is true once you fix the commen
| |
32 } | |
33 | |
34 ZoomView::~ZoomView() { | |
35 } | |
36 | |
37 void ZoomView::SetZoomIconState(ZoomController::ZoomIconState zoom_icon_state) { | |
38 if (zoom_icon_state == zoom_icon_state_) | |
39 return; | |
40 | |
41 zoom_icon_state_ = zoom_icon_state; | |
42 Update(); | |
43 } | |
44 | |
45 void ZoomView::SetZoomIconTooltipPercent(int zoom_percent) { | |
46 if (zoom_percent == zoom_percent_) | |
47 return; | |
48 | |
49 zoom_percent_ = zoom_percent; | |
50 Update(); | |
51 } | |
52 | |
53 void ZoomView::Update() { | |
54 if (toolbar_model_->input_in_progress() || | |
55 zoom_icon_state_ == ZoomController::NONE) { | |
56 SetVisible(false); | |
57 ZoomBubbleView::CloseBubble(); | |
58 } else { | |
59 SetVisible(true); | |
60 SetTooltipText( | |
61 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent_)); | |
62 int resource_id = zoom_icon_state_ == ZoomController::ZOOM_PLUS_ICON ? | |
Peter Kasting
2012/06/26 23:23:39
Nit: You could also inline this into the next stat
Kyle Horimoto
2012/06/30 00:22:50
Done.
| |
63 IDR_ZOOM_PLUS : IDR_ZOOM_MINUS; | |
64 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
65 resource_id)); | |
66 } | |
67 } | |
68 | |
69 void ZoomView::GetAccessibleState(ui::AccessibleViewState* state) { | |
70 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM); | |
71 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | |
72 } | |
73 | |
74 bool ZoomView::GetTooltipText(const gfx::Point& p, string16* tooltip) const { | |
75 // Don't show tooltip if the zoom bubble is displayed. | |
76 if (ZoomBubbleView::IsShowing()) | |
Peter Kasting
2012/06/26 23:23:39
Nit: Shorter:
return !ZoomBubbleView::IsShowing
Kyle Horimoto
2012/06/30 00:22:50
Done.
| |
77 return false; | |
78 | |
79 return ImageView::GetTooltipText(p, tooltip); | |
80 } | |
81 | |
82 bool ZoomView::OnMousePressed(const views::MouseEvent& event) { | |
83 // Do nothing until mouse is released. | |
84 return true; | |
85 } | |
86 | |
87 void ZoomView::OnMouseReleased(const views::MouseEvent& event) { | |
88 if (event.IsOnlyLeftMouseButton() && HitTest(event.location())) | |
89 ZoomBubbleView::ShowBubble(this, zoom_percent_, false); | |
90 } | |
91 | |
92 bool ZoomView::OnKeyPressed(const views::KeyEvent& event) { | |
93 if (event.key_code() != ui::VKEY_SPACE && | |
94 event.key_code() != ui::VKEY_RETURN) | |
95 return false; | |
96 | |
97 ZoomBubbleView::ShowBubble(this, zoom_percent_, false); | |
98 return true; | |
99 } | |
OLD | NEW |