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

Side by Side Diff: ash/system/tray_caps_lock.cc

Issue 10269017: Remove scoped_ptr for system tray views (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 7 months 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
« no previous file with comments | « ash/system/tray_caps_lock.h ('k') | ash/system/tray_update.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "ash/system/tray_caps_lock.h" 5 #include "ash/system/tray_caps_lock.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/tray/system_tray_delegate.h" 8 #include "ash/system/tray/system_tray_delegate.h"
9 #include "ash/system/tray/tray_constants.h" 9 #include "ash/system/tray/tray_constants.h"
10 #include "ash/system/tray/tray_views.h" 10 #include "ash/system/tray/tray_views.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 91 }
92 92
93 views::Label* text_label_; 93 views::Label* text_label_;
94 views::Label* shortcut_label_; 94 views::Label* shortcut_label_;
95 95
96 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView); 96 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView);
97 }; 97 };
98 98
99 TrayCapsLock::TrayCapsLock() 99 TrayCapsLock::TrayCapsLock()
100 : TrayImageItem(IDR_AURA_UBER_TRAY_CAPS_LOCK), 100 : TrayImageItem(IDR_AURA_UBER_TRAY_CAPS_LOCK),
101 default_(NULL),
102 detailed_(NULL),
101 search_mapped_to_caps_lock_(false), 103 search_mapped_to_caps_lock_(false),
102 caps_lock_enabled_( 104 caps_lock_enabled_(
103 Shell::GetInstance()->tray_delegate()->IsCapsLockOn()) { 105 Shell::GetInstance()->tray_delegate()->IsCapsLockOn()) {
104 } 106 }
105 107
106 TrayCapsLock::~TrayCapsLock() {} 108 TrayCapsLock::~TrayCapsLock() {}
107 109
108 bool TrayCapsLock::GetInitialVisibility() { 110 bool TrayCapsLock::GetInitialVisibility() {
109 return Shell::GetInstance()->tray_delegate()->IsCapsLockOn(); 111 return Shell::GetInstance()->tray_delegate()->IsCapsLockOn();
110 } 112 }
111 113
112 views::View* TrayCapsLock::CreateDefaultView(user::LoginStatus status) { 114 views::View* TrayCapsLock::CreateDefaultView(user::LoginStatus status) {
113 if (!caps_lock_enabled_) 115 if (!caps_lock_enabled_)
114 return NULL; 116 return NULL;
115 default_.reset(new CapsLockDefaultView); 117 DCHECK(default_ == NULL);
118 default_ = new CapsLockDefaultView;
116 default_->Update(caps_lock_enabled_, search_mapped_to_caps_lock_); 119 default_->Update(caps_lock_enabled_, search_mapped_to_caps_lock_);
117 return default_.get(); 120 return default_;
118 } 121 }
119 122
120 views::View* TrayCapsLock::CreateDetailedView(user::LoginStatus status) { 123 views::View* TrayCapsLock::CreateDetailedView(user::LoginStatus status) {
121 detailed_.reset(new views::View); 124 DCHECK(detailed_ == NULL);
125 detailed_ = new views::View;
122 126
123 detailed_->SetLayoutManager(new 127 detailed_->SetLayoutManager(new
124 views::BoxLayout(views::BoxLayout::kHorizontal, 128 views::BoxLayout(views::BoxLayout::kHorizontal,
125 kTrayPopupPaddingHorizontal, 10, kTrayPopupPaddingBetweenItems)); 129 kTrayPopupPaddingHorizontal, 10, kTrayPopupPaddingBetweenItems));
126 130
127 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 131 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
128 views::ImageView* image = new views::ImageView; 132 views::ImageView* image = new views::ImageView;
129 image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK). 133 image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK).
130 ToSkBitmap()); 134 ToSkBitmap());
131 135
132 detailed_->AddChildView(image); 136 detailed_->AddChildView(image);
133 137
134 const int string_id = search_mapped_to_caps_lock_ ? 138 const int string_id = search_mapped_to_caps_lock_ ?
135 IDS_ASH_STATUS_TRAY_CAPS_LOCK_ENABLED_PRESS_SEARCH : 139 IDS_ASH_STATUS_TRAY_CAPS_LOCK_ENABLED_PRESS_SEARCH :
136 IDS_ASH_STATUS_TRAY_CAPS_LOCK_ENABLED_PRESS_SHIFT_AND_SEARCH_KEYS; 140 IDS_ASH_STATUS_TRAY_CAPS_LOCK_ENABLED_PRESS_SHIFT_AND_SEARCH_KEYS;
137 detailed_->AddChildView( 141 detailed_->AddChildView(
138 new views::Label(bundle.GetLocalizedString(string_id))); 142 new views::Label(bundle.GetLocalizedString(string_id)));
139 143
140 return detailed_.get(); 144 return detailed_;
141 } 145 }
142 146
143 void TrayCapsLock::DestroyDefaultView() { 147 void TrayCapsLock::DestroyDefaultView() {
144 default_.reset(); 148 default_ = NULL;
145 } 149 }
146 150
147 void TrayCapsLock::DestroyDetailedView() { 151 void TrayCapsLock::DestroyDetailedView() {
148 detailed_.reset(); 152 detailed_ = NULL;
149 } 153 }
150 154
151 void TrayCapsLock::OnCapsLockChanged(bool enabled, 155 void TrayCapsLock::OnCapsLockChanged(bool enabled,
152 bool search_mapped_to_caps_lock) { 156 bool search_mapped_to_caps_lock) {
153 if (tray_view()) 157 if (tray_view())
154 tray_view()->SetVisible(enabled); 158 tray_view()->SetVisible(enabled);
155 159
156 caps_lock_enabled_ = enabled; 160 caps_lock_enabled_ = enabled;
157 search_mapped_to_caps_lock_ = search_mapped_to_caps_lock; 161 search_mapped_to_caps_lock_ = search_mapped_to_caps_lock;
158 162
159 if (default_.get()) { 163 if (default_) {
160 default_->Update(enabled, search_mapped_to_caps_lock); 164 default_->Update(enabled, search_mapped_to_caps_lock);
161 } else { 165 } else {
162 if (enabled) 166 if (enabled)
163 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 167 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
164 else if (detailed_.get()) 168 else if (detailed_)
165 detailed_->GetWidget()->Close(); 169 detailed_->GetWidget()->Close();
166 } 170 }
167 } 171 }
168 172
169 } // namespace internal 173 } // namespace internal
170 } // namespace ash 174 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray_caps_lock.h ('k') | ash/system/tray_update.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698