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 | |
16 ZoomView::ZoomView() | |
17 // Initially set the icon state to the plus icon even if it should be | |
18 // something else so that the location bar's layout can account for the | |
19 // width needed to display it. | |
Peter Kasting
2012/06/22 20:16:20
? I don't understand why this is important.
Would
Kyle Horimoto
2012/06/26 21:55:53
I set it to NONE, and directly called SetImageSize
| |
20 : zoom_icon_state_(ZoomController::ZOOM_PLUS_ICON), | |
21 zoom_percent_(100) { | |
22 set_id(VIEW_ID_ZOOM_BUTTON); | |
23 set_accessibility_focusable(true); | |
24 | |
25 Update(); | |
26 } | |
27 | |
28 ZoomView::~ZoomView() { | |
29 } | |
30 | |
31 void ZoomView::SetZoomIconState(ZoomController::ZoomIconState zoom_icon_state) { | |
32 if (zoom_icon_state == zoom_icon_state_) | |
33 return; | |
34 | |
35 zoom_icon_state_ = zoom_icon_state; | |
36 Update(); | |
37 } | |
38 | |
39 void ZoomView::SetZoomIconTooltipPercent(int zoom_percent) { | |
40 if (zoom_percent == zoom_percent_) | |
41 return; | |
42 | |
43 zoom_percent_ = zoom_percent; | |
44 Update(); | |
45 } | |
46 | |
47 void ZoomView::Update() { | |
48 switch (zoom_icon_state_) { | |
49 case ZoomController::NONE: | |
50 SetVisible(false); | |
Peter Kasting
2012/06/22 20:16:20
I don't like that both the location bar and this c
Kyle Horimoto
2012/06/26 21:55:53
Done. Good idea - this is far more elegant.
| |
51 ZoomBubbleView::CloseBubble(); | |
52 break; | |
53 | |
54 case ZoomController::ZOOM_PLUS_ICON: | |
55 SetVisible(true); | |
56 SetTooltipText( | |
57 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent_)); | |
58 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
59 IDR_ZOOM_PLUS)); | |
60 break; | |
61 | |
62 case ZoomController::ZOOM_MINUS_ICON: | |
63 SetVisible(true); | |
64 SetTooltipText( | |
65 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent_)); | |
66 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
67 IDR_ZOOM_MINUS)); | |
68 break; | |
69 | |
70 default: | |
71 NOTREACHED(); | |
72 } | |
73 } | |
74 | |
75 void ZoomView::GetAccessibleState(ui::AccessibleViewState* state) { | |
76 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM); | |
77 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | |
78 } | |
79 | |
80 bool ZoomView::GetTooltipText(const gfx::Point& p, string16* tooltip) const { | |
81 // Don't show tooltip if the zoom bubble is displayed. | |
82 if (ZoomBubbleView::IsShowing()) | |
83 return false; | |
84 | |
85 return ImageView::GetTooltipText(p, tooltip); | |
86 } | |
87 | |
88 bool ZoomView::OnMousePressed(const views::MouseEvent& event) { | |
89 // Do nothing until mouse is released. | |
90 return true; | |
91 } | |
92 | |
93 void ZoomView::OnMouseReleased(const views::MouseEvent& event) { | |
94 if (event.IsOnlyLeftMouseButton() && HitTest(event.location())) | |
95 ZoomBubbleView::ShowBubble(this, zoom_percent_, false); | |
96 } | |
97 | |
98 bool ZoomView::OnKeyPressed(const views::KeyEvent& event) { | |
99 if (event.key_code() == ui::VKEY_SPACE || | |
Peter Kasting
2012/06/22 20:16:20
Nit: If you reverse this conditional you can avoid
Kyle Horimoto
2012/06/26 21:55:53
Done.
| |
100 event.key_code() == ui::VKEY_RETURN) { | |
101 ZoomBubbleView::ShowBubble(this, zoom_percent_, false); | |
102 return true; | |
103 } | |
104 return false; | |
105 } | |
OLD | NEW |