| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 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/translate_icon_view.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/command_updater.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/view_ids.h" |
| 12 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" |
| 13 #include "grit/generated_resources.h" |
| 14 #include "grit/theme_resources.h" |
| 15 #include "ui/base/accessibility/accessible_view_state.h" |
| 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/resource/resource_bundle.h" |
| 18 |
| 19 TranslateIconView::TranslateIconView( |
| 20 CommandUpdater* command_updater) |
| 21 : command_updater_(command_updater), |
| 22 suppress_mouse_released_action_(false) { |
| 23 set_id(VIEW_ID_TRANSLATE_BUTTON); |
| 24 SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_TRANSLATE)); |
| 25 ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance(); |
| 26 SetImage(resource_bundle.GetImageSkiaNamed(IDR_TRANSLATE)); |
| 27 set_accessibility_focusable(true); |
| 28 } |
| 29 |
| 30 TranslateIconView::~TranslateIconView() { |
| 31 } |
| 32 |
| 33 void TranslateIconView::GetAccessibleState( |
| 34 ui::AccessibleViewState* state) { |
| 35 ImageView::GetAccessibleState(state); |
| 36 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 37 } |
| 38 |
| 39 bool TranslateIconView::GetTooltipText(const gfx::Point& p, |
| 40 string16* tooltip) const { |
| 41 if (TranslateBubbleView::IsShowing()) |
| 42 return false; |
| 43 |
| 44 return views::ImageView::GetTooltipText(p, tooltip); |
| 45 } |
| 46 |
| 47 bool TranslateIconView::OnMousePressed(const ui::MouseEvent& event) { |
| 48 // If the translate bubble is showing then don't reshow it when the mouse is |
| 49 // released. |
| 50 suppress_mouse_released_action_ = false; |
| 51 |
| 52 // We want to show the bubble on mouse release; that is the standard behavior |
| 53 // for buttons. |
| 54 return true; |
| 55 } |
| 56 |
| 57 void TranslateIconView::OnMouseReleased(const ui::MouseEvent& event) { |
| 58 // If this is the second click on this view then the translate bubble was |
| 59 // showing on the mouse pressed event and is hidden now. Prevent the bubble |
| 60 // from reshowing by doing nothing here. |
| 61 if (suppress_mouse_released_action_) { |
| 62 suppress_mouse_released_action_ = false; |
| 63 return; |
| 64 } |
| 65 |
| 66 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) |
| 67 command_updater_->ExecuteCommand(IDC_TRANSLATE_PAGE); |
| 68 } |
| 69 |
| 70 bool TranslateIconView::OnKeyPressed(const ui::KeyEvent& event) { |
| 71 if (event.key_code() == ui::VKEY_SPACE || |
| 72 event.key_code() == ui::VKEY_RETURN) { |
| 73 command_updater_->ExecuteCommand(IDC_TRANSLATE_PAGE); |
| 74 return true; |
| 75 } |
| 76 return false; |
| 77 } |
| 78 |
| 79 void TranslateIconView::OnGestureEvent(ui::GestureEvent* event) { |
| 80 if (event->type() == ui::ET_GESTURE_TAP) { |
| 81 command_updater_->ExecuteCommand(IDC_TRANSLATE_PAGE); |
| 82 event->SetHandled(); |
| 83 } |
| 84 } |
| OLD | NEW |