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 "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
12 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
13 #include "ui/accessibility/ax_view_state.h" | 13 #include "ui/accessibility/ax_view_state.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
17 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
18 | 18 |
19 ZoomView::ZoomView(LocationBarView::Delegate* location_bar_delegate) | 19 ZoomView::ZoomView(LocationBarView::Delegate* location_bar_delegate) |
20 : location_bar_delegate_(location_bar_delegate) { | 20 : location_bar_delegate_(location_bar_delegate), |
| 21 was_bubble_showing_(false) { |
21 SetAccessibilityFocusable(true); | 22 SetAccessibilityFocusable(true); |
22 Update(NULL); | 23 Update(NULL); |
23 } | 24 } |
24 | 25 |
25 ZoomView::~ZoomView() { | 26 ZoomView::~ZoomView() { |
26 } | 27 } |
27 | 28 |
28 void ZoomView::Update(ZoomController* zoom_controller) { | 29 void ZoomView::Update(ZoomController* zoom_controller) { |
29 if (!zoom_controller || zoom_controller->IsAtDefaultZoom() || | 30 if (!zoom_controller || zoom_controller->IsAtDefaultZoom() || |
30 location_bar_delegate_->GetToolbarModel()->input_in_progress()) { | 31 location_bar_delegate_->GetToolbarModel()->input_in_progress()) { |
(...skipping 14 matching lines...) Expand all Loading... |
45 state->role = ui::AX_ROLE_BUTTON; | 46 state->role = ui::AX_ROLE_BUTTON; |
46 } | 47 } |
47 | 48 |
48 bool ZoomView::GetTooltipText(const gfx::Point& p, | 49 bool ZoomView::GetTooltipText(const gfx::Point& p, |
49 base::string16* tooltip) const { | 50 base::string16* tooltip) const { |
50 // Don't show tooltip if the zoom bubble is displayed. | 51 // Don't show tooltip if the zoom bubble is displayed. |
51 return !ZoomBubbleView::IsShowing() && ImageView::GetTooltipText(p, tooltip); | 52 return !ZoomBubbleView::IsShowing() && ImageView::GetTooltipText(p, tooltip); |
52 } | 53 } |
53 | 54 |
54 bool ZoomView::OnMousePressed(const ui::MouseEvent& event) { | 55 bool ZoomView::OnMousePressed(const ui::MouseEvent& event) { |
| 56 // The Zoom bubble has its own widget. By the time this code is reached, it's |
| 57 // already lost activation and is closing as mouse presses on other widgets |
| 58 // immediately call Close(). |
| 59 was_bubble_showing_ = ZoomBubbleView::IsClosing(); |
| 60 |
55 // Do nothing until mouse is released. | 61 // Do nothing until mouse is released. |
56 return true; | 62 return true; |
57 } | 63 } |
58 | 64 |
59 void ZoomView::OnMouseReleased(const ui::MouseEvent& event) { | 65 void ZoomView::OnMouseReleased(const ui::MouseEvent& event) { |
| 66 if (was_bubble_showing_) { |
| 67 was_bubble_showing_ = false; |
| 68 return; |
| 69 } |
| 70 |
60 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) | 71 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) |
61 ActivateBubble(); | 72 ToggleBubble(); |
62 } | 73 } |
63 | 74 |
64 bool ZoomView::OnKeyPressed(const ui::KeyEvent& event) { | 75 bool ZoomView::OnKeyPressed(const ui::KeyEvent& event) { |
65 if (event.key_code() != ui::VKEY_SPACE && | 76 if (event.key_code() != ui::VKEY_SPACE && |
66 event.key_code() != ui::VKEY_RETURN) { | 77 event.key_code() != ui::VKEY_RETURN) { |
67 return false; | 78 return false; |
68 } | 79 } |
69 | 80 |
70 ActivateBubble(); | 81 ToggleBubble(); |
71 return true; | 82 return true; |
72 } | 83 } |
73 | 84 |
74 void ZoomView::OnGestureEvent(ui::GestureEvent* event) { | 85 void ZoomView::OnGestureEvent(ui::GestureEvent* event) { |
75 if (event->type() == ui::ET_GESTURE_TAP) { | 86 if (event->type() == ui::ET_GESTURE_TAP) { |
76 ActivateBubble(); | 87 ToggleBubble(); |
77 event->SetHandled(); | 88 event->SetHandled(); |
78 } | 89 } |
79 } | 90 } |
80 | 91 |
81 void ZoomView::ActivateBubble() { | 92 void ZoomView::ToggleBubble() { |
82 ZoomBubbleView::ShowBubble(location_bar_delegate_->GetWebContents(), false); | 93 if (ZoomBubbleView::IsShowing()) |
| 94 ZoomBubbleView::CloseBubble(); |
| 95 else |
| 96 ZoomBubbleView::ShowBubble(location_bar_delegate_->GetWebContents(), false); |
83 } | 97 } |
OLD | NEW |