| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/status/caps_lock_menu_button.h" | 5 #include "chrome/browser/chromeos/status/caps_lock_menu_button.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/input_method/xkeyboard.h" | 10 #include "chrome/browser/chromeos/input_method/xkeyboard.h" |
| 11 #include "chrome/browser/chromeos/system/runtime_environment.h" | 11 #include "chrome/browser/chromeos/system/runtime_environment.h" |
| 12 #include "chrome/browser/chromeos/view_ids.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/ui/views/bubble/bubble.h" | 15 #include "chrome/browser/ui/views/bubble/bubble.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 22 #include "ui/gfx/canvas_skia.h" | 23 #include "ui/gfx/canvas_skia.h" |
| 23 #include "ui/gfx/font.h" | 24 #include "ui/gfx/font.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 34 const int kImageWidth = 22, kImageHeight = 21; | 35 const int kImageWidth = 22, kImageHeight = 21; |
| 35 // Constants for status displayed when user clicks button. | 36 // Constants for status displayed when user clicks button. |
| 36 // Padding around status. | 37 // Padding around status. |
| 37 const int kPadLeftX = 10, kPadRightX = 10, kPadY = 5; | 38 const int kPadLeftX = 10, kPadRightX = 10, kPadY = 5; |
| 38 // Padding between image and text. | 39 // Padding between image and text. |
| 39 const int kTextPadX = 10; | 40 const int kTextPadX = 10; |
| 40 | 41 |
| 41 const size_t kMaxBubbleCount = 3; | 42 const size_t kMaxBubbleCount = 3; |
| 42 const size_t kCloseBubbleTimerInSec = 5; | 43 const size_t kCloseBubbleTimerInSec = 5; |
| 43 | 44 |
| 44 // Returns PrefService object associated with |host|. | 45 PrefService* GetPrefService() { |
| 45 PrefService* GetPrefService(chromeos::StatusAreaHost* host) { | 46 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 46 if (host->GetProfile()) | 47 if (profile) |
| 47 return host->GetProfile()->GetPrefs(); | 48 return profile->GetPrefs(); |
| 48 return NULL; | 49 return NULL; |
| 49 } | 50 } |
| 50 | 51 |
| 51 } // namespace | 52 } // namespace |
| 52 | 53 |
| 53 namespace chromeos { | 54 namespace chromeos { |
| 54 | 55 |
| 55 class CapsLockMenuButton::StatusView : public View { | 56 class CapsLockMenuButton::StatusView : public View { |
| 56 public: | 57 public: |
| 57 explicit StatusView(CapsLockMenuButton* menu_button) | 58 explicit StatusView(CapsLockMenuButton* menu_button) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 private: | 139 private: |
| 139 CapsLockMenuButton* menu_button_; | 140 CapsLockMenuButton* menu_button_; |
| 140 gfx::Font font_; | 141 gfx::Font font_; |
| 141 | 142 |
| 142 DISALLOW_COPY_AND_ASSIGN(StatusView); | 143 DISALLOW_COPY_AND_ASSIGN(StatusView); |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 //////////////////////////////////////////////////////////////////////////////// | 146 //////////////////////////////////////////////////////////////////////////////// |
| 146 // CapsLockMenuButton | 147 // CapsLockMenuButton |
| 147 | 148 |
| 148 CapsLockMenuButton::CapsLockMenuButton(StatusAreaHost* host) | 149 CapsLockMenuButton::CapsLockMenuButton(StatusAreaButton::Delegate* delegate) |
| 149 : StatusAreaButton(host, this), | 150 : StatusAreaButton(delegate, this), |
| 150 prefs_(GetPrefService(host)), | 151 prefs_(GetPrefService()), |
| 151 status_(NULL), | 152 status_(NULL), |
| 152 bubble_(NULL), | 153 bubble_(NULL), |
| 153 should_show_bubble_(true), | 154 should_show_bubble_(true), |
| 154 bubble_count_(0) { | 155 bubble_count_(0) { |
| 156 set_id(VIEW_ID_STATUS_BUTTON_CAPS_LOCK); |
| 155 if (prefs_) | 157 if (prefs_) |
| 156 remap_search_key_to_.Init( | 158 remap_search_key_to_.Init( |
| 157 prefs::kLanguageXkbRemapSearchKeyTo, prefs_, this); | 159 prefs::kLanguageXkbRemapSearchKeyTo, prefs_, this); |
| 158 | 160 |
| 159 SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( | 161 SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 160 IDR_STATUSBAR_CAPS_LOCK)); | 162 IDR_STATUSBAR_CAPS_LOCK)); |
| 161 UpdateAccessibleName(); | 163 UpdateAccessibleName(); |
| 162 UpdateUIFromCurrentCapsLock(input_method::XKeyboard::CapsLockIsEnabled()); | 164 UpdateUIFromCurrentCapsLock(input_method::XKeyboard::CapsLockIsEnabled()); |
| 163 if (SystemKeyEventListener::GetInstance()) | 165 if (SystemKeyEventListener::GetInstance()) |
| 164 SystemKeyEventListener::GetInstance()->AddCapsLockObserver(this); | 166 SystemKeyEventListener::GetInstance()->AddCapsLockObserver(this); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 } | 335 } |
| 334 | 336 |
| 335 bool CapsLockMenuButton::HasCapsLock() const { | 337 bool CapsLockMenuButton::HasCapsLock() const { |
| 336 return (prefs_ && | 338 return (prefs_ && |
| 337 (remap_search_key_to_.GetValue() == input_method::kCapsLockKey)) || | 339 (remap_search_key_to_.GetValue() == input_method::kCapsLockKey)) || |
| 338 // A keyboard for Linux usually has Caps Lock. | 340 // A keyboard for Linux usually has Caps Lock. |
| 339 !system::runtime_environment::IsRunningOnChromeOS(); | 341 !system::runtime_environment::IsRunningOnChromeOS(); |
| 340 } | 342 } |
| 341 | 343 |
| 342 } // namespace chromeos | 344 } // namespace chromeos |
| OLD | NEW |