| Index: chrome/browser/ui/views/location_bar/translate_icon_view.cc
|
| diff --git a/chrome/browser/ui/views/location_bar/translate_icon_view.cc b/chrome/browser/ui/views/location_bar/translate_icon_view.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cb1bfe7f45e8acb4591ac43932e8b4fc0935367c
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/location_bar/translate_icon_view.cc
|
| @@ -0,0 +1,84 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/views/location_bar/translate_icon_view.h"
|
| +
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "chrome/app/chrome_command_ids.h"
|
| +#include "chrome/browser/command_updater.h"
|
| +#include "chrome/browser/ui/browser_commands.h"
|
| +#include "chrome/browser/ui/view_ids.h"
|
| +#include "chrome/browser/ui/views/translate/translate_bubble_view.h"
|
| +#include "grit/generated_resources.h"
|
| +#include "grit/theme_resources.h"
|
| +#include "ui/base/accessibility/accessible_view_state.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
| +#include "ui/base/resource/resource_bundle.h"
|
| +
|
| +TranslateIconView::TranslateIconView(
|
| + CommandUpdater* command_updater)
|
| + : command_updater_(command_updater),
|
| + suppress_mouse_released_action_(false) {
|
| + set_id(VIEW_ID_TRANSLATE_BUTTON);
|
| + SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_TRANSLATE));
|
| + ui::ResourceBundle& resource_bundle = ui::ResourceBundle::GetSharedInstance();
|
| + SetImage(resource_bundle.GetImageSkiaNamed(IDR_TRANSLATE));
|
| + set_accessibility_focusable(true);
|
| +}
|
| +
|
| +TranslateIconView::~TranslateIconView() {
|
| +}
|
| +
|
| +void TranslateIconView::GetAccessibleState(
|
| + ui::AccessibleViewState* state) {
|
| + ImageView::GetAccessibleState(state);
|
| + state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
|
| +}
|
| +
|
| +bool TranslateIconView::GetTooltipText(const gfx::Point& p,
|
| + string16* tooltip) const {
|
| + if (TranslateBubbleView::IsShowing())
|
| + return false;
|
| +
|
| + return views::ImageView::GetTooltipText(p, tooltip);
|
| +}
|
| +
|
| +bool TranslateIconView::OnMousePressed(const ui::MouseEvent& event) {
|
| + // If the translate bubble is showing then don't reshow it when the mouse is
|
| + // released.
|
| + suppress_mouse_released_action_ = false;
|
| +
|
| + // We want to show the bubble on mouse release; that is the standard behavior
|
| + // for buttons.
|
| + return true;
|
| +}
|
| +
|
| +void TranslateIconView::OnMouseReleased(const ui::MouseEvent& event) {
|
| + // If this is the second click on this view then the translate bubble was
|
| + // showing on the mouse pressed event and is hidden now. Prevent the bubble
|
| + // from reshowing by doing nothing here.
|
| + if (suppress_mouse_released_action_) {
|
| + suppress_mouse_released_action_ = false;
|
| + return;
|
| + }
|
| +
|
| + if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location()))
|
| + command_updater_->ExecuteCommand(IDC_TRANSLATE_PAGE);
|
| +}
|
| +
|
| +bool TranslateIconView::OnKeyPressed(const ui::KeyEvent& event) {
|
| + if (event.key_code() == ui::VKEY_SPACE ||
|
| + event.key_code() == ui::VKEY_RETURN) {
|
| + command_updater_->ExecuteCommand(IDC_TRANSLATE_PAGE);
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +void TranslateIconView::OnGestureEvent(ui::GestureEvent* event) {
|
| + if (event->type() == ui::ET_GESTURE_TAP) {
|
| + command_updater_->ExecuteCommand(IDC_TRANSLATE_PAGE);
|
| + event->SetHandled();
|
| + }
|
| +}
|
|
|