OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/views/location_bar/metro_pin_view.h" | |
6 | |
7 #include "base/utf_string_conversions.h" | |
8 #include "chrome/app/chrome_command_ids.h" | |
9 #include "chrome/browser/command_updater.h" | |
10 #include "chrome/browser/ui/view_ids.h" | |
11 #include "chrome/browser/ui/views/browser_dialogs.h" | |
12 #include "grit/generated_resources.h" | |
13 #include "grit/theme_resources.h" | |
14 #include "ui/base/accessibility/accessible_view_state.h" | |
15 #include "ui/base/l10n/l10n_util.h" | |
16 #include "ui/base/resource/resource_bundle.h" | |
17 | |
18 MetroPinView::MetroPinView(CommandUpdater* command_updater) | |
19 : command_updater_(command_updater) { | |
20 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.
| |
21 SetIsPinned(false); | |
22 set_accessibility_focusable(true); | |
23 TouchableLocationBarView::Init(this); | |
24 } | |
25 | |
26 MetroPinView::~MetroPinView() { | |
27 } | |
28 | |
29 void MetroPinView::SetIsPinned(bool is_pinned) { | |
30 SetTooltipText(l10n_util::GetStringUTF16( | |
31 is_pinned ? IDS_TOOLTIP_METRO_PINNED : IDS_TOOLTIP_METRO_PIN)); | |
32 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
33 is_pinned ? IDR_METRO_PINNED : IDR_METRO_PIN)); | |
34 } | |
35 | |
36 int MetroPinView::GetBuiltInHorizontalPadding() const { | |
37 return GetBuiltInHorizontalPaddingImpl(); | |
38 } | |
39 | |
40 void MetroPinView::GetAccessibleState(ui::AccessibleViewState* state) { | |
41 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_METRO_PIN); | |
42 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | |
43 } | |
44 | |
45 bool MetroPinView::OnMousePressed(const views::MouseEvent& event) { | |
46 // 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!
| |
47 // for buttons. | |
48 return true; | |
49 } | |
50 | |
51 void MetroPinView::OnMouseReleased(const views::MouseEvent& event) { | |
52 if (event.IsOnlyLeftMouseButton() && HitTest(event.location())) | |
53 command_updater_->ExecuteCommand(IDC_METRO_PIN_TO_START_SCREEN); | |
54 } | |
55 | |
56 ui::GestureStatus MetroPinView::OnGestureEvent( | |
57 const views::GestureEvent& event) { | |
58 if (event.type() == ui::ET_GESTURE_TAP) { | |
59 command_updater_->ExecuteCommand(IDC_METRO_PIN_TO_START_SCREEN); | |
60 return ui::GESTURE_STATUS_CONSUMED; | |
61 } | |
62 return ui::GESTURE_STATUS_UNKNOWN; | |
63 } | |
64 | |
65 bool MetroPinView::OnKeyPressed(const views::KeyEvent& event) { | |
66 if (event.key_code() == ui::VKEY_SPACE || | |
67 event.key_code() == ui::VKEY_RETURN) { | |
68 command_updater_->ExecuteCommand(IDC_METRO_PIN_TO_START_SCREEN); | |
69 return true; | |
70 } | |
71 return false; | |
72 } | |
OLD | NEW |