| 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/chrome_to_mobile_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 "chrome/browser/ui/views/location_bar/location_bar_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/event.h" | |
| 17 #include "ui/base/l10n/l10n_util.h" | |
| 18 #include "ui/base/resource/resource_bundle.h" | |
| 19 | |
| 20 ChromeToMobileView::ChromeToMobileView( | |
| 21 LocationBarView* location_bar_view, | |
| 22 CommandUpdater* command_updater) | |
| 23 : location_bar_view_(location_bar_view), | |
| 24 command_updater_(command_updater) { | |
| 25 set_id(VIEW_ID_CHROME_TO_MOBILE_BUTTON); | |
| 26 set_accessibility_focusable(true); | |
| 27 SetImage( | |
| 28 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(IDR_MOBILE)); | |
| 29 SetTooltipText( | |
| 30 l10n_util::GetStringUTF16(IDS_CHROME_TO_MOBILE_BUBBLE_TOOLTIP)); | |
| 31 SetVisible(command_updater_->IsCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE)); | |
| 32 command_updater_->AddCommandObserver(IDC_CHROME_TO_MOBILE_PAGE, this); | |
| 33 TouchableLocationBarView::Init(this); | |
| 34 } | |
| 35 | |
| 36 ChromeToMobileView::~ChromeToMobileView() { | |
| 37 command_updater_->RemoveCommandObserver(IDC_CHROME_TO_MOBILE_PAGE, this); | |
| 38 } | |
| 39 | |
| 40 void ChromeToMobileView::EnabledStateChangedForCommand(int id, bool enabled) { | |
| 41 DCHECK_EQ(id, IDC_CHROME_TO_MOBILE_PAGE); | |
| 42 if (enabled != visible()) { | |
| 43 SetVisible(enabled); | |
| 44 location_bar_view_->Update(NULL); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 int ChromeToMobileView::GetBuiltInHorizontalPadding() const { | |
| 49 return GetBuiltInHorizontalPaddingImpl(); | |
| 50 } | |
| 51 | |
| 52 void ChromeToMobileView::GetAccessibleState(ui::AccessibleViewState* state) { | |
| 53 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_CHROME_TO_MOBILE); | |
| 54 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | |
| 55 } | |
| 56 | |
| 57 bool ChromeToMobileView::GetTooltipText(const gfx::Point& p, | |
| 58 string16* tooltip) const { | |
| 59 // Don't show tooltip to distract user if ChromeToMobileBubbleView is showing. | |
| 60 if (chrome::IsChromeToMobileBubbleViewShowing()) | |
| 61 return false; | |
| 62 | |
| 63 return views::ImageView::GetTooltipText(p, tooltip); | |
| 64 } | |
| 65 | |
| 66 bool ChromeToMobileView::OnMousePressed(const ui::MouseEvent& event) { | |
| 67 // Show the bubble on mouse release; that is standard button behavior. | |
| 68 return true; | |
| 69 } | |
| 70 | |
| 71 void ChromeToMobileView::OnMouseReleased(const ui::MouseEvent& event) { | |
| 72 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) | |
| 73 command_updater_->ExecuteCommand(IDC_CHROME_TO_MOBILE_PAGE); | |
| 74 } | |
| 75 | |
| 76 bool ChromeToMobileView::OnKeyPressed(const ui::KeyEvent& event) { | |
| 77 if (event.key_code() == ui::VKEY_SPACE || | |
| 78 event.key_code() == ui::VKEY_RETURN) { | |
| 79 command_updater_->ExecuteCommand(IDC_CHROME_TO_MOBILE_PAGE); | |
| 80 return true; | |
| 81 } | |
| 82 return false; | |
| 83 } | |
| OLD | NEW |