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_view.h" | 5 #include "chrome/browser/ui/views/location_bar/zoom_view.h" |
6 | 6 |
7 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 7 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
8 #include "chrome/browser/ui/view_ids.h" | 8 #include "chrome/browser/ui/view_ids.h" |
9 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | 9 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
10 #include "chrome/browser/ui/zoom/zoom_controller.h" | 10 #include "chrome/browser/ui/zoom/zoom_controller.h" |
11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
12 #include "ui/accessibility/ax_view_state.h" | 12 #include "ui/accessibility/ax_view_state.h" |
13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
17 | 17 |
18 ZoomView::ZoomView(LocationBarView::Delegate* location_bar_delegate) | 18 ZoomView::ZoomView(LocationBarView::Delegate* location_bar_delegate) |
19 : location_bar_delegate_(location_bar_delegate) { | 19 : BubbleIconView(nullptr, 0), |
20 SetAccessibilityFocusable(true); | 20 location_bar_delegate_(location_bar_delegate) { |
21 Update(NULL); | 21 Update(NULL); |
22 } | 22 } |
23 | 23 |
24 ZoomView::~ZoomView() { | 24 ZoomView::~ZoomView() { |
25 } | 25 } |
26 | 26 |
27 void ZoomView::Update(ZoomController* zoom_controller) { | 27 void ZoomView::Update(ZoomController* zoom_controller) { |
28 if (!zoom_controller || zoom_controller->IsAtDefaultZoom() || | 28 if (!zoom_controller || zoom_controller->IsAtDefaultZoom() || |
29 location_bar_delegate_->GetToolbarModel()->input_in_progress()) { | 29 location_bar_delegate_->GetToolbarModel()->input_in_progress()) { |
30 SetVisible(false); | 30 SetVisible(false); |
31 ZoomBubbleView::CloseBubble(); | 31 ZoomBubbleView::CloseBubble(); |
32 return; | 32 return; |
33 } | 33 } |
34 | 34 |
35 SetTooltipText(l10n_util::GetStringFUTF16Int( | 35 SetTooltipText(l10n_util::GetStringFUTF16Int( |
36 IDS_TOOLTIP_ZOOM, zoom_controller->GetZoomPercent())); | 36 IDS_TOOLTIP_ZOOM, zoom_controller->GetZoomPercent())); |
37 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 37 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
38 zoom_controller->GetResourceForZoomLevel())); | 38 zoom_controller->GetResourceForZoomLevel())); |
39 SetVisible(true); | 39 SetVisible(true); |
40 } | 40 } |
41 | 41 |
42 void ZoomView::GetAccessibleState(ui::AXViewState* state) { | 42 void ZoomView::GetAccessibleState(ui::AXViewState* state) { |
msw
2014/10/24 00:39:48
nit: make the definition order match the decl orde
Dan Beam
2014/10/24 00:44:19
Done.
| |
43 BubbleIconView::GetAccessibleState(state); | |
43 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM); | 44 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM); |
44 state->role = ui::AX_ROLE_BUTTON; | |
45 } | 45 } |
46 | 46 |
47 bool ZoomView::GetTooltipText(const gfx::Point& p, | 47 bool ZoomView::IsBubbleShowing() const { |
48 base::string16* tooltip) const { | 48 return ZoomBubbleView::IsShowing(); |
49 // Don't show tooltip if the zoom bubble is displayed. | |
50 return !ZoomBubbleView::IsShowing() && ImageView::GetTooltipText(p, tooltip); | |
51 } | 49 } |
52 | 50 |
53 bool ZoomView::OnMousePressed(const ui::MouseEvent& event) { | 51 void ZoomView::OnExecuting(BubbleIconView::ExecuteSource source) { |
54 // Do nothing until mouse is released. | |
55 return true; | |
56 } | |
57 | |
58 void ZoomView::OnMouseReleased(const ui::MouseEvent& event) { | |
59 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) | |
60 ActivateBubble(); | |
61 } | |
62 | |
63 bool ZoomView::OnKeyPressed(const ui::KeyEvent& event) { | |
64 if (event.key_code() != ui::VKEY_SPACE && | |
65 event.key_code() != ui::VKEY_RETURN) { | |
66 return false; | |
67 } | |
68 | |
69 ActivateBubble(); | |
70 return true; | |
71 } | |
72 | |
73 void ZoomView::OnGestureEvent(ui::GestureEvent* event) { | |
74 if (event->type() == ui::ET_GESTURE_TAP) { | |
75 ActivateBubble(); | |
76 event->SetHandled(); | |
77 } | |
78 } | |
79 | |
80 void ZoomView::ActivateBubble() { | |
81 ZoomBubbleView::ShowBubble(location_bar_delegate_->GetWebContents(), false); | 52 ZoomBubbleView::ShowBubble(location_bar_delegate_->GetWebContents(), false); |
82 } | 53 } |
OLD | NEW |