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

Side by Side Diff: ash/system/web_notification/web_notification_tray.cc

Issue 176883022: Shelf Cleanup (- binary files) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 9 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/user/tray_user.cc ('k') | ash/test/shelf_view_test_api.cc » ('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/web_notification/web_notification_tray.h" 5 #include "ash/system/web_notification/web_notification_tray.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/root_window_controller.h" 8 #include "ash/root_window_controller.h"
9 #include "ash/shelf/shelf_layout_manager.h" 9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_layout_manager_observer.h" 10 #include "ash/shelf/shelf_layout_manager_observer.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 StopObserving(); 117 StopObserving();
118 } 118 }
119 119
120 void WorkAreaObserver::SetSystemTrayHeight(int height) { 120 void WorkAreaObserver::SetSystemTrayHeight(int height) {
121 system_tray_height_ = height; 121 system_tray_height_ = height;
122 122
123 // If the shelf is shown during auto-hide state, the distance from the edge 123 // If the shelf is shown during auto-hide state, the distance from the edge
124 // should be reduced by the height of shelf's shown height. 124 // should be reduced by the height of shelf's shown height.
125 if (shelf_ && shelf_->visibility_state() == SHELF_AUTO_HIDE && 125 if (shelf_ && shelf_->visibility_state() == SHELF_AUTO_HIDE &&
126 shelf_->auto_hide_state() == SHELF_AUTO_HIDE_SHOWN) { 126 shelf_->auto_hide_state() == SHELF_AUTO_HIDE_SHOWN) {
127 system_tray_height_ -= ShelfLayoutManager::GetPreferredShelfSize() - 127 system_tray_height_ -= kShelfSize - ShelfLayoutManager::kAutoHideSize;
128 ShelfLayoutManager::kAutoHideSize;
129 } 128 }
130 129
131 if (system_tray_height_ > 0 && ash::switches::UseAlternateShelfLayout()) 130 if (system_tray_height_ > 0)
132 system_tray_height_ += message_center::kMarginBetweenItems; 131 system_tray_height_ += message_center::kMarginBetweenItems;
133 132
134 if (!shelf_) 133 if (!shelf_)
135 return; 134 return;
136 135
137 OnAutoHideStateChanged(shelf_->auto_hide_state()); 136 OnAutoHideStateChanged(shelf_->auto_hide_state());
138 } 137 }
139 138
140 void WorkAreaObserver::StartObserving( 139 void WorkAreaObserver::StartObserving(
141 message_center::MessagePopupCollection* collection, 140 message_center::MessagePopupCollection* collection,
(...skipping 25 matching lines...) Expand all
167 166
168 void WorkAreaObserver::OnAutoHideStateChanged(ShelfAutoHideState new_state) { 167 void WorkAreaObserver::OnAutoHideStateChanged(ShelfAutoHideState new_state) {
169 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( 168 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow(
170 shelf_->shelf_widget()->GetNativeView()); 169 shelf_->shelf_widget()->GetNativeView());
171 gfx::Rect work_area = display.work_area(); 170 gfx::Rect work_area = display.work_area();
172 int width = 0; 171 int width = 0;
173 if ((shelf_->visibility_state() == SHELF_AUTO_HIDE) && 172 if ((shelf_->visibility_state() == SHELF_AUTO_HIDE) &&
174 new_state == SHELF_AUTO_HIDE_SHOWN) { 173 new_state == SHELF_AUTO_HIDE_SHOWN) {
175 // Since the work_area is already reduced by kAutoHideSize, the inset width 174 // Since the work_area is already reduced by kAutoHideSize, the inset width
176 // should be just the difference. 175 // should be just the difference.
177 width = ShelfLayoutManager::GetPreferredShelfSize() - 176 width = kShelfSize - ShelfLayoutManager::kAutoHideSize;
178 ShelfLayoutManager::kAutoHideSize;
179 } 177 }
180 work_area.Inset(shelf_->SelectValueForShelfAlignment( 178 work_area.Inset(shelf_->SelectValueForShelfAlignment(
181 gfx::Insets(0, 0, width, 0), 179 gfx::Insets(0, 0, width, 0),
182 gfx::Insets(0, width, 0, 0), 180 gfx::Insets(0, width, 0, 0),
183 gfx::Insets(0, 0, 0, width), 181 gfx::Insets(0, 0, 0, width),
184 gfx::Insets(width, 0, 0, 0))); 182 gfx::Insets(width, 0, 0, 0)));
185 if (system_tray_height_ > 0) { 183 if (system_tray_height_ > 0) {
186 work_area.set_height( 184 work_area.set_height(
187 std::max(0, work_area.height() - system_tray_height_)); 185 std::max(0, work_area.height() - system_tray_height_));
188 if (shelf_->GetAlignment() == SHELF_ALIGNMENT_TOP) 186 if (shelf_->GetAlignment() == SHELF_ALIGNMENT_TOP)
(...skipping 24 matching lines...) Expand all
213 views::TrayBubbleView::InitParams init_params = 211 views::TrayBubbleView::InitParams init_params =
214 bubble->GetInitParams(anchor_alignment); 212 bubble->GetInitParams(anchor_alignment);
215 views::View* anchor = tray->tray_container(); 213 views::View* anchor = tray->tray_container();
216 if (anchor_alignment == views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { 214 if (anchor_alignment == views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
217 gfx::Point bounds(anchor->width() / 2, 0); 215 gfx::Point bounds(anchor->width() / 2, 0);
218 views::View::ConvertPointToWidget(anchor, &bounds); 216 views::View::ConvertPointToWidget(anchor, &bounds);
219 init_params.arrow_offset = bounds.x(); 217 init_params.arrow_offset = bounds.x();
220 } 218 }
221 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( 219 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create(
222 tray->GetBubbleWindowContainer(), anchor, tray, &init_params); 220 tray->GetBubbleWindowContainer(), anchor, tray, &init_params);
223 if (ash::switches::UseAlternateShelfLayout()) 221 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
224 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
225 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); 222 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view));
226 bubble->InitializeContents(bubble_view); 223 bubble->InitializeContents(bubble_view);
227 } 224 }
228 225
229 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } 226 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); }
230 227
231 // Convenience accessors. 228 // Convenience accessors.
232 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } 229 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); }
233 230
234 private: 231 private:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // in ash_strings. 263 // in ash_strings.
267 unread_label_->SetText((unread_count > 9) ? 264 unread_label_->SetText((unread_count > 9) ?
268 l10n_util::GetStringUTF16(IDS_ASH_NOTIFICATION_UNREAD_COUNT_NINE_PLUS) : 265 l10n_util::GetStringUTF16(IDS_ASH_NOTIFICATION_UNREAD_COUNT_NINE_PLUS) :
269 base::FormatNumber(unread_count)); 266 base::FormatNumber(unread_count));
270 UpdateIconVisibility(); 267 UpdateIconVisibility();
271 } 268 }
272 269
273 protected: 270 protected:
274 // Overridden from views::ImageButton: 271 // Overridden from views::ImageButton:
275 virtual gfx::Size GetPreferredSize() OVERRIDE { 272 virtual gfx::Size GetPreferredSize() OVERRIDE {
276 const int notification_item_size = GetShelfItemHeight(); 273 return gfx::Size(kShelfItemHeight, kShelfItemHeight);
277 return gfx::Size(notification_item_size, notification_item_size);
278 } 274 }
279 275
280 virtual int GetHeightForWidth(int width) OVERRIDE { 276 virtual int GetHeightForWidth(int width) OVERRIDE {
281 return GetPreferredSize().height(); 277 return GetPreferredSize().height();
282 } 278 }
283 279
284 private: 280 private:
285 void UpdateIconVisibility() { 281 void UpdateIconVisibility() {
286 unread_label_->SetEnabledColor( 282 unread_label_->SetEnabledColor(
287 (!is_bubble_visible_ && unread_count_ > 0) ? 283 (!is_bubble_visible_ && unread_count_ > 0) ?
(...skipping 27 matching lines...) Expand all
315 SetVisible(false); 311 SetVisible(false);
316 message_center_tray_.reset(new message_center::MessageCenterTray( 312 message_center_tray_.reset(new message_center::MessageCenterTray(
317 this, 313 this,
318 message_center::MessageCenter::Get())); 314 message_center::MessageCenter::Get()));
319 popup_collection_.reset(new message_center::MessagePopupCollection( 315 popup_collection_.reset(new message_center::MessagePopupCollection(
320 ash::Shell::GetContainer( 316 ash::Shell::GetContainer(
321 status_area_widget->GetNativeView()->GetRootWindow(), 317 status_area_widget->GetNativeView()->GetRootWindow(),
322 internal::kShellWindowId_StatusContainer), 318 internal::kShellWindowId_StatusContainer),
323 message_center(), 319 message_center(),
324 message_center_tray_.get(), 320 message_center_tray_.get(),
325 ash::switches::UseAlternateShelfLayout())); 321 true));
326 work_area_observer_.reset(new internal::WorkAreaObserver()); 322 work_area_observer_.reset(new internal::WorkAreaObserver());
327 work_area_observer_->StartObserving( 323 work_area_observer_->StartObserving(
328 popup_collection_.get(), 324 popup_collection_.get(),
329 status_area_widget->GetNativeView()->GetRootWindow()); 325 status_area_widget->GetNativeView()->GetRootWindow());
330 OnMessageCenterTrayChanged(); 326 OnMessageCenterTrayChanged();
331 } 327 }
332 328
333 WebNotificationTray::~WebNotificationTray() { 329 WebNotificationTray::~WebNotificationTray() {
334 // Release any child views that might have back pointers before ~View(). 330 // Release any child views that might have back pointers before ~View().
335 message_center_bubble_.reset(); 331 message_center_bubble_.reset();
336 popup_collection_.reset(); 332 popup_collection_.reset();
337 work_area_observer_.reset(); 333 work_area_observer_.reset();
338 } 334 }
339 335
340 // Public methods. 336 // Public methods.
341 337
342 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { 338 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) {
343 if (!ShouldShowMessageCenter()) 339 if (!ShouldShowMessageCenter())
344 return false; 340 return false;
345 341
346 should_block_shelf_auto_hide_ = true; 342 should_block_shelf_auto_hide_ = true;
347 message_center::MessageCenterBubble* message_center_bubble = 343 message_center::MessageCenterBubble* message_center_bubble =
348 new message_center::MessageCenterBubble( 344 new message_center::MessageCenterBubble(
349 message_center(), 345 message_center(),
350 message_center_tray_.get(), 346 message_center_tray_.get(),
351 ash::switches::UseAlternateShelfLayout()); 347 true);
352 348
353 int max_height = 0; 349 int max_height = 0;
354 aura::Window* status_area_window = status_area_widget()->GetNativeView(); 350 aura::Window* status_area_window = status_area_widget()->GetNativeView();
355 switch (GetShelfLayoutManager()->GetAlignment()) { 351 switch (GetShelfLayoutManager()->GetAlignment()) {
356 case SHELF_ALIGNMENT_BOTTOM: { 352 case SHELF_ALIGNMENT_BOTTOM: {
357 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds(); 353 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds();
358 max_height = shelf_bounds.y(); 354 max_height = shelf_bounds.y();
359 break; 355 break;
360 } 356 }
361 case SHELF_ALIGNMENT_TOP: { 357 case SHELF_ALIGNMENT_TOP: {
362 aura::Window* root = status_area_window->GetRootWindow(); 358 aura::Window* root = status_area_window->GetRootWindow();
363 max_height = 359 max_height =
364 root->bounds().height() - status_area_window->bounds().height(); 360 root->bounds().height() - status_area_window->bounds().height();
365 break; 361 break;
366 } 362 }
367 case SHELF_ALIGNMENT_LEFT: 363 case SHELF_ALIGNMENT_LEFT:
368 case SHELF_ALIGNMENT_RIGHT: { 364 case SHELF_ALIGNMENT_RIGHT: {
369 // Assume that the bottom line of the status area widget and the bubble 365 // Assume that the bottom line of the status area widget and the bubble
370 // are aligned. 366 // are aligned.
371 max_height = status_area_window->GetBoundsInRootWindow().bottom(); 367 max_height = status_area_window->GetBoundsInRootWindow().bottom();
372 break; 368 break;
373 } 369 }
374 default: 370 default:
375 NOTREACHED(); 371 NOTREACHED();
376 } 372 }
377 373
378 message_center_bubble->SetMaxHeight(std::max(0, 374 message_center_bubble->SetMaxHeight(std::max(0,
379 max_height - GetTraySpacing())); 375 max_height - kTraySpacing));
380 if (show_settings) 376 if (show_settings)
381 message_center_bubble->SetSettingsVisible(); 377 message_center_bubble->SetSettingsVisible();
382 message_center_bubble_.reset( 378 message_center_bubble_.reset(
383 new internal::WebNotificationBubbleWrapper(this, message_center_bubble)); 379 new internal::WebNotificationBubbleWrapper(this, message_center_bubble));
384 380
385 status_area_widget()->SetHideSystemNotifications(true); 381 status_area_widget()->SetHideSystemNotifications(true);
386 GetShelfLayoutManager()->UpdateAutoHideState(); 382 GetShelfLayoutManager()->UpdateAutoHideState();
387 button_->SetBubbleVisible(true); 383 button_->SetBubbleVisible(true);
388 SetDrawBackgroundAsActive(true); 384 SetDrawBackgroundAsActive(true);
389 return true; 385 return true;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 616
621 message_center::MessageCenterBubble* 617 message_center::MessageCenterBubble*
622 WebNotificationTray::GetMessageCenterBubbleForTest() { 618 WebNotificationTray::GetMessageCenterBubbleForTest() {
623 if (!message_center_bubble()) 619 if (!message_center_bubble())
624 return NULL; 620 return NULL;
625 return static_cast<message_center::MessageCenterBubble*>( 621 return static_cast<message_center::MessageCenterBubble*>(
626 message_center_bubble()->bubble()); 622 message_center_bubble()->bubble());
627 } 623 }
628 624
629 } // namespace ash 625 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/user/tray_user.cc ('k') | ash/test/shelf_view_test_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698