Index: chrome/browser/ui/views/location_bar/metro_pin_view.cc |
diff --git a/chrome/browser/ui/views/location_bar/metro_pin_view.cc b/chrome/browser/ui/views/location_bar/metro_pin_view.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..693a4f609e9937df2e535671a8bb621ca49269ce |
--- /dev/null |
+++ b/chrome/browser/ui/views/location_bar/metro_pin_view.cc |
@@ -0,0 +1,72 @@ |
+// Copyright (c) 2012 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/metro_pin_view.h" |
+ |
+#include "base/utf_string_conversions.h" |
+#include "chrome/app/chrome_command_ids.h" |
+#include "chrome/browser/command_updater.h" |
+#include "chrome/browser/ui/view_ids.h" |
+#include "chrome/browser/ui/views/browser_dialogs.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" |
+ |
+MetroPinView::MetroPinView(CommandUpdater* command_updater) |
+ : command_updater_(command_updater) { |
+ set_id(VIEW_ID_STAR_BUTTON); |
sky
2012/07/20 16:46:41
This isn't the right id.
benwells
2012/07/23 08:03:43
Done.
|
+ SetIsPinned(false); |
+ set_accessibility_focusable(true); |
+ TouchableLocationBarView::Init(this); |
+} |
+ |
+MetroPinView::~MetroPinView() { |
+} |
+ |
+void MetroPinView::SetIsPinned(bool is_pinned) { |
+ SetTooltipText(l10n_util::GetStringUTF16( |
+ is_pinned ? IDS_TOOLTIP_METRO_PINNED : IDS_TOOLTIP_METRO_PIN)); |
+ SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
+ is_pinned ? IDR_METRO_PINNED : IDR_METRO_PIN)); |
+} |
+ |
+int MetroPinView::GetBuiltInHorizontalPadding() const { |
+ return GetBuiltInHorizontalPaddingImpl(); |
+} |
+ |
+void MetroPinView::GetAccessibleState(ui::AccessibleViewState* state) { |
+ state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_METRO_PIN); |
+ state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
+} |
+ |
+bool MetroPinView::OnMousePressed(const views::MouseEvent& event) { |
+ // We want to show the bubble on mouse release; that is the standard behavior |
sky
2012/07/20 16:46:41
The reason StarView isn't a button is that it show
benwells
2012/07/23 08:03:43
Cool, that's much better!
|
+ // for buttons. |
+ return true; |
+} |
+ |
+void MetroPinView::OnMouseReleased(const views::MouseEvent& event) { |
+ if (event.IsOnlyLeftMouseButton() && HitTest(event.location())) |
+ command_updater_->ExecuteCommand(IDC_METRO_PIN_TO_START_SCREEN); |
+} |
+ |
+ui::GestureStatus MetroPinView::OnGestureEvent( |
+ const views::GestureEvent& event) { |
+ if (event.type() == ui::ET_GESTURE_TAP) { |
+ command_updater_->ExecuteCommand(IDC_METRO_PIN_TO_START_SCREEN); |
+ return ui::GESTURE_STATUS_CONSUMED; |
+ } |
+ return ui::GESTURE_STATUS_UNKNOWN; |
+} |
+ |
+bool MetroPinView::OnKeyPressed(const views::KeyEvent& event) { |
+ if (event.key_code() == ui::VKEY_SPACE || |
+ event.key_code() == ui::VKEY_RETURN) { |
+ command_updater_->ExecuteCommand(IDC_METRO_PIN_TO_START_SCREEN); |
+ return true; |
+ } |
+ return false; |
+} |