Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: chrome/browser/chromeos/status/caps_lock_menu_button.cc

Issue 8438064: Separate StatusAreaView from StatusAreaViewChromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/status/status_area_bubble.h" 11 #include "chrome/browser/chromeos/status/status_area_bubble.h"
12 #include "chrome/browser/chromeos/system/runtime_environment.h" 12 #include "chrome/browser/chromeos/system/runtime_environment.h"
13 #include "chrome/browser/chromeos/view_ids.h"
13 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile_manager.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/image/image.h" 22 #include "ui/gfx/image/image.h"
22 #include "views/controls/image_view.h" 23 #include "views/controls/image_view.h"
23 #include "views/controls/menu/menu_item_view.h" 24 #include "views/controls/menu/menu_item_view.h"
24 #include "views/controls/menu/menu_runner.h" 25 #include "views/controls/menu/menu_runner.h"
25 #include "views/controls/menu/submenu_view.h" 26 #include "views/controls/menu/submenu_view.h"
26 #include "views/widget/widget.h" 27 #include "views/widget/widget.h"
27 28
28 namespace { 29 namespace {
29 30
30 const size_t kMaxBubbleCount = 3; 31 const size_t kMaxBubbleCount = 3;
31 32
32 // Returns PrefService object associated with |host|. 33 PrefService* GetPrefService() {
33 PrefService* GetPrefService(chromeos::StatusAreaHost* host) { 34 Profile* profile = ProfileManager::GetDefaultProfile();
34 if (host->GetProfile()) 35 if (profile)
35 return host->GetProfile()->GetPrefs(); 36 return profile->GetPrefs();
36 return NULL; 37 return NULL;
37 } 38 }
38 39
39 views::ImageView* CreateImageViewWithCapsLockIcon() { 40 views::ImageView* CreateImageViewWithCapsLockIcon() {
40 const gfx::Image& image = 41 const gfx::Image& image =
41 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_CAPS_LOCK_ICON); 42 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_CAPS_LOCK_ICON);
42 views::ImageView* image_view = new views::ImageView; 43 views::ImageView* image_view = new views::ImageView;
43 image_view->SetImage(image.ToSkBitmap()); 44 image_view->SetImage(image.ToSkBitmap());
44 return image_view; 45 return image_view;
45 } 46 }
46 47
47 } // namespace 48 } // namespace
48 49
49 namespace chromeos { 50 namespace chromeos {
50 51
51 //////////////////////////////////////////////////////////////////////////////// 52 ////////////////////////////////////////////////////////////////////////////////
52 // CapsLockMenuButton 53 // CapsLockMenuButton
53 54
54 CapsLockMenuButton::CapsLockMenuButton(StatusAreaHost* host) 55 CapsLockMenuButton::CapsLockMenuButton(StatusAreaButton::Delegate* delegate)
55 : StatusAreaButton(host, this), 56 : StatusAreaButton(delegate, this),
56 prefs_(GetPrefService(host)), 57 prefs_(GetPrefService()),
57 status_(NULL), 58 status_(NULL),
58 should_show_bubble_(true), 59 should_show_bubble_(true),
59 bubble_count_(0) { 60 bubble_count_(0) {
61 set_id(VIEW_ID_STATUS_BUTTON_CAPS_LOCK);
60 if (prefs_) 62 if (prefs_)
61 remap_search_key_to_.Init( 63 remap_search_key_to_.Init(
62 prefs::kLanguageXkbRemapSearchKeyTo, prefs_, this); 64 prefs::kLanguageXkbRemapSearchKeyTo, prefs_, this);
63 65
64 SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed( 66 SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(
65 IDR_STATUSBAR_CAPS_LOCK)); 67 IDR_STATUSBAR_CAPS_LOCK));
66 UpdateAccessibleName(); 68 UpdateAccessibleName();
67 UpdateUIFromCurrentCapsLock(input_method::XKeyboard::CapsLockIsEnabled()); 69 UpdateUIFromCurrentCapsLock(input_method::XKeyboard::CapsLockIsEnabled());
68 if (SystemKeyEventListener::GetInstance()) 70 if (SystemKeyEventListener::GetInstance())
69 SystemKeyEventListener::GetInstance()->AddCapsLockObserver(this); 71 SystemKeyEventListener::GetInstance()->AddCapsLockObserver(this);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 229 }
228 230
229 bool CapsLockMenuButton::HasCapsLock() const { 231 bool CapsLockMenuButton::HasCapsLock() const {
230 return (prefs_ && 232 return (prefs_ &&
231 (remap_search_key_to_.GetValue() == input_method::kCapsLockKey)) || 233 (remap_search_key_to_.GetValue() == input_method::kCapsLockKey)) ||
232 // A keyboard for Linux usually has Caps Lock. 234 // A keyboard for Linux usually has Caps Lock.
233 !system::runtime_environment::IsRunningOnChromeOS(); 235 !system::runtime_environment::IsRunningOnChromeOS();
234 } 236 }
235 237
236 } // namespace chromeos 238 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698