| 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 #ifndef CHROME_BROWSER_CHROMEOS_STATUS_CAPS_LOCK_MENU_BUTTON_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_STATUS_CAPS_LOCK_MENU_BUTTON_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/timer.h" | |
| 13 #include "chrome/browser/chromeos/status/status_area_button.h" | |
| 14 #include "chrome/browser/chromeos/system_key_event_listener.h" | |
| 15 #include "chrome/browser/prefs/pref_member.h" | |
| 16 #include "content/public/browser/notification_observer.h" | |
| 17 #include "content/public/browser/notification_registrar.h" | |
| 18 #include "ui/views/controls/button/menu_button_listener.h" | |
| 19 #include "ui/views/controls/menu/menu_delegate.h" | |
| 20 | |
| 21 class Bubble; | |
| 22 | |
| 23 namespace views { | |
| 24 class MenuRunner; | |
| 25 } | |
| 26 | |
| 27 namespace chromeos { | |
| 28 | |
| 29 class StatusAreaBubbleContentView; | |
| 30 class StatusAreaBubbleController; | |
| 31 | |
| 32 // A class for the button in the status area which alerts the user when caps | |
| 33 // lock is active. | |
| 34 class CapsLockMenuButton : public content::NotificationObserver, | |
| 35 public StatusAreaButton, | |
| 36 public views::MenuDelegate, | |
| 37 public views::MenuButtonListener, | |
| 38 public SystemKeyEventListener::CapsLockObserver { | |
| 39 public: | |
| 40 explicit CapsLockMenuButton(StatusAreaButton::Delegate* delegate); | |
| 41 virtual ~CapsLockMenuButton(); | |
| 42 | |
| 43 // views::View implementation. | |
| 44 virtual void OnLocaleChanged() OVERRIDE; | |
| 45 | |
| 46 // views::MenuDelegate implementation. | |
| 47 virtual string16 GetLabel(int id) const OVERRIDE; | |
| 48 | |
| 49 // views::MenuButtonListener implementation. | |
| 50 virtual void OnMenuButtonClicked(views::View* source, | |
| 51 const gfx::Point& point) OVERRIDE; | |
| 52 | |
| 53 // SystemKeyEventListener::CapsLockObserver implementation | |
| 54 virtual void OnCapsLockChange(bool enabled) OVERRIDE; | |
| 55 | |
| 56 // content::NotificationObserver implementation | |
| 57 virtual void Observe(int type, | |
| 58 const content::NotificationSource& source, | |
| 59 const content::NotificationDetails& details) OVERRIDE; | |
| 60 | |
| 61 private: | |
| 62 // Returns true if the Search key is assigned to Caps Lock. | |
| 63 bool HasCapsLock() const; | |
| 64 | |
| 65 bool IsMenuShown() const; | |
| 66 void HideMenu(); | |
| 67 | |
| 68 bool IsBubbleShown() const; | |
| 69 void MaybeShowBubble(); | |
| 70 void CreateAndShowBubble(); | |
| 71 void HideBubble(); | |
| 72 | |
| 73 // Updates the accessible name. | |
| 74 void UpdateAccessibleName(); | |
| 75 | |
| 76 // Gets the text for the drop-down menu and bubble. | |
| 77 string16 GetText() const; | |
| 78 | |
| 79 // Updates the button from the current state. | |
| 80 void UpdateUIFromCurrentCapsLock(bool enabled); | |
| 81 | |
| 82 // Initializes |remap_search_key_to_|. | |
| 83 void InitializePrefMember(); | |
| 84 | |
| 85 bool initialized_prefs_; | |
| 86 content::NotificationRegistrar registrar_; | |
| 87 | |
| 88 IntegerPrefMember remap_search_key_to_; | |
| 89 | |
| 90 // The currently showing status view. NULL if menu is not being displayed. | |
| 91 StatusAreaBubbleContentView* status_; | |
| 92 // If non-null the menu is showing. | |
| 93 scoped_ptr<views::MenuRunner> menu_runner_; | |
| 94 | |
| 95 // The currently showing bubble controller. | |
| 96 // NULL if bubble is not being displayed. | |
| 97 scoped_ptr<StatusAreaBubbleController> bubble_controller_; | |
| 98 // If true, |bubble_| is shown when both shift keys are pressed. | |
| 99 bool should_show_bubble_; | |
| 100 // # of times |bubble_| is shown. | |
| 101 size_t bubble_count_; | |
| 102 // TODO(yusukes): Save should_show_bubble_ and bubble_count_ in Preferences. | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(CapsLockMenuButton); | |
| 105 }; | |
| 106 | |
| 107 } // namespace chromeos | |
| 108 | |
| 109 #endif // CHROME_BROWSER_CHROMEOS_STATUS_CAPS_LOCK_MENU_BUTTON_H_ | |
| OLD | NEW |