OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/location_bar/star_view.h" | 5 #include "chrome/browser/views/location_bar/star_view.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "chrome/app/chrome_dll_resource.h" | 9 #include "chrome/app/chrome_dll_resource.h" |
10 #include "chrome/browser/command_updater.h" | 10 #include "chrome/browser/command_updater.h" |
11 #include "chrome/browser/view_ids.h" | 11 #include "chrome/browser/view_ids.h" |
| 12 #include "chrome/browser/views/browser_dialogs.h" |
12 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
13 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
14 | 15 |
15 StarView::StarView(CommandUpdater* command_updater) | 16 StarView::StarView(CommandUpdater* command_updater) |
16 : command_updater_(command_updater) { | 17 : command_updater_(command_updater) { |
17 SetID(VIEW_ID_STAR_BUTTON); | 18 SetID(VIEW_ID_STAR_BUTTON); |
18 SetToggled(false); | 19 SetToggled(false); |
19 set_accessibility_focusable(true); | 20 set_accessibility_focusable(true); |
20 } | 21 } |
21 | 22 |
22 StarView::~StarView() { | 23 StarView::~StarView() { |
23 } | 24 } |
24 | 25 |
25 void StarView::SetToggled(bool on) { | 26 void StarView::SetToggled(bool on) { |
26 SetTooltipText(l10n_util::GetString( | 27 SetTooltipText(l10n_util::GetString( |
27 on ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR)); | 28 on ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR)); |
28 // Since StarView is an ImageView, the SetTooltipText changes the accessible | 29 // Since StarView is an ImageView, the SetTooltipText changes the accessible |
29 // name. To keep the accessible name unchanged, we need to set the accessible | 30 // name. To keep the accessible name unchanged, we need to set the accessible |
30 // name right after we modify the tooltip text for this view. | 31 // name right after we modify the tooltip text for this view. |
31 SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_STAR)); | 32 SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_STAR)); |
32 SetImage(ResourceBundle::GetSharedInstance().GetBitmapNamed( | 33 SetImage(ResourceBundle::GetSharedInstance().GetBitmapNamed( |
33 on ? IDR_OMNIBOX_STAR_LIT : IDR_OMNIBOX_STAR)); | 34 on ? IDR_OMNIBOX_STAR_LIT : IDR_OMNIBOX_STAR)); |
34 } | 35 } |
35 | 36 |
36 bool StarView::GetAccessibleRole(AccessibilityTypes::Role* role) { | 37 bool StarView::GetAccessibleRole(AccessibilityTypes::Role* role) { |
37 *role = AccessibilityTypes::ROLE_PUSHBUTTON; | 38 *role = AccessibilityTypes::ROLE_PUSHBUTTON; |
38 return true; | 39 return true; |
39 } | 40 } |
40 | 41 |
| 42 bool StarView::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { |
| 43 // Don't show tooltip to distract user if BookmarkBubbleView is showing. |
| 44 if (browser::IsBookmarkBubbleViewShowing()) |
| 45 return false; |
| 46 |
| 47 return ImageView::GetTooltipText(p, tooltip); |
| 48 } |
| 49 |
41 bool StarView::OnMousePressed(const views::MouseEvent& event) { | 50 bool StarView::OnMousePressed(const views::MouseEvent& event) { |
42 // We want to show the bubble on mouse release; that is the standard behavior | 51 // We want to show the bubble on mouse release; that is the standard behavior |
43 // for buttons. | 52 // for buttons. |
44 return true; | 53 return true; |
45 } | 54 } |
46 | 55 |
47 void StarView::OnMouseReleased(const views::MouseEvent& event, bool canceled) { | 56 void StarView::OnMouseReleased(const views::MouseEvent& event, bool canceled) { |
48 if (!canceled && HitTest(event.location())) | 57 if (!canceled && HitTest(event.location())) |
49 command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE); | 58 command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE); |
50 } | 59 } |
51 | 60 |
52 bool StarView::OnKeyPressed(const views::KeyEvent& e) { | 61 bool StarView::OnKeyPressed(const views::KeyEvent& e) { |
53 if (e.GetKeyCode() == base::VKEY_SPACE || | 62 if (e.GetKeyCode() == base::VKEY_SPACE || |
54 e.GetKeyCode() == base::VKEY_RETURN) { | 63 e.GetKeyCode() == base::VKEY_RETURN) { |
55 command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE); | 64 command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE); |
56 return true; | 65 return true; |
57 } | 66 } |
58 return false; | 67 return false; |
59 } | 68 } |
60 | 69 |
61 void StarView::InfoBubbleClosing(InfoBubble* info_bubble, | 70 void StarView::InfoBubbleClosing(InfoBubble* info_bubble, |
62 bool closed_by_escape) { | 71 bool closed_by_escape) { |
63 } | 72 } |
64 | 73 |
65 bool StarView::CloseOnEscape() { | 74 bool StarView::CloseOnEscape() { |
66 return true; | 75 return true; |
67 } | 76 } |
OLD | NEW |