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

Side by Side Diff: ash/system/tray/system_tray_bubble.cc

Issue 10384178: ash: Make sure all the sub-popups retain the same height as the main popup. (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/system_tray_bubble.h ('k') | ash/system/tray/system_tray_item.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/system_tray_bubble.h" 5 #include "ash/system/tray/system_tray_bubble.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 8 #include "ash/shell_window_ids.h"
9 #include "ash/system/tray/system_tray.h" 9 #include "ash/system/tray/system_tray.h"
10 #include "ash/system/tray/system_tray_delegate.h"
10 #include "ash/system/tray/system_tray_item.h" 11 #include "ash/system/tray/system_tray_item.h"
11 #include "ash/system/tray/tray_constants.h" 12 #include "ash/system/tray/tray_constants.h"
12 #include "ash/wm/shelf_layout_manager.h" 13 #include "ash/wm/shelf_layout_manager.h"
13 #include "ash/wm/window_animations.h" 14 #include "ash/wm/window_animations.h"
14 #include "base/message_loop.h" 15 #include "base/message_loop.h"
15 #include "grit/ash_strings.h" 16 #include "grit/ash_strings.h"
16 #include "third_party/skia/include/core/SkCanvas.h" 17 #include "third_party/skia/include/core/SkCanvas.h"
17 #include "third_party/skia/include/core/SkColor.h" 18 #include "third_party/skia/include/core/SkColor.h"
18 #include "third_party/skia/include/core/SkPaint.h" 19 #include "third_party/skia/include/core/SkPaint.h"
19 #include "third_party/skia/include/core/SkPath.h" 20 #include "third_party/skia/include/core/SkPath.h"
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 void SystemTrayBubbleView::SetBubbleBorder(views::BubbleBorder* border) { 263 void SystemTrayBubbleView::SetBubbleBorder(views::BubbleBorder* border) {
263 GetBubbleFrameView()->SetBubbleBorder(border); 264 GetBubbleFrameView()->SetBubbleBorder(border);
264 } 265 }
265 266
266 void SystemTrayBubbleView::UpdateAnchor() { 267 void SystemTrayBubbleView::UpdateAnchor() {
267 SizeToContents(); 268 SizeToContents();
268 GetWidget()->GetRootView()->SchedulePaint(); 269 GetWidget()->GetRootView()->SchedulePaint();
269 } 270 }
270 271
271 void SystemTrayBubbleView::Init() { 272 void SystemTrayBubbleView::Init() {
272 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 1, 1, 1)); 273 views::BoxLayout* layout =
274 new views::BoxLayout(views::BoxLayout::kVertical, 1, 1, 1);
275 layout->set_spread_blank_space(true);
276 SetLayoutManager(layout);
273 set_background(new SystemTrayBubbleBackground(this)); 277 set_background(new SystemTrayBubbleBackground(this));
274 } 278 }
275 279
276 gfx::Rect SystemTrayBubbleView::GetAnchorRect() { 280 gfx::Rect SystemTrayBubbleView::GetAnchorRect() {
277 gfx::Rect rect; 281 gfx::Rect rect;
278 if (host_) 282 if (host_)
279 rect = host_->GetAnchorRect(); 283 rect = host_->GetAnchorRect();
280 if (rect.IsEmpty()) { 284 if (rect.IsEmpty()) {
281 rect = gfx::Screen::GetPrimaryMonitor().bounds(); 285 rect = gfx::Screen::GetPrimaryMonitor().bounds();
282 rect = gfx::Rect(base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreen : 286 rect = gfx::Rect(base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreen :
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // Reset the host pointer in bubble_view_ in case its destruction is deferred. 346 // Reset the host pointer in bubble_view_ in case its destruction is deferred.
343 if (bubble_view_) 347 if (bubble_view_)
344 bubble_view_->reset_host(); 348 bubble_view_->reset_host();
345 if (bubble_widget_) { 349 if (bubble_widget_) {
346 bubble_widget_->RemoveObserver(this); 350 bubble_widget_->RemoveObserver(this);
347 // This triggers the destruction of bubble_view_. 351 // This triggers the destruction of bubble_view_.
348 bubble_widget_->Close(); 352 bubble_widget_->Close();
349 } 353 }
350 } 354 }
351 355
356 void SystemTrayBubble::UpdateView(
357 const std::vector<ash::SystemTrayItem*>& items,
358 BubbleType bubble_type) {
359 DestroyItemViews();
360 bubble_view_->RemoveAllChildViews(true);
361
362 items_ = items;
363 bubble_type_ = bubble_type;
364 CreateItemViews(Shell::GetInstance()->tray_delegate()->GetUserLoginStatus());
365 bubble_widget_->GetContentsView()->Layout();
366 }
367
352 void SystemTrayBubble::InitView(views::View* anchor, 368 void SystemTrayBubble::InitView(views::View* anchor,
353 AnchorType anchor_type, 369 AnchorType anchor_type,
354 bool can_activate, 370 bool can_activate,
355 ash::user::LoginStatus login_status) { 371 ash::user::LoginStatus login_status) {
356 DCHECK(bubble_view_ == NULL); 372 DCHECK(bubble_view_ == NULL);
357 anchor_type_ = anchor_type; 373 anchor_type_ = anchor_type;
358 bubble_view_ = new SystemTrayBubbleView(anchor, this, can_activate); 374 bubble_view_ = new SystemTrayBubbleView(anchor, this, can_activate);
359 375
360 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin(); 376 CreateItemViews(login_status);
361 it != items_.end();
362 ++it) {
363 views::View* view = NULL;
364 switch (bubble_type_) {
365 case BUBBLE_TYPE_DEFAULT:
366 view = (*it)->CreateDefaultView(login_status);
367 break;
368 case BUBBLE_TYPE_DETAILED:
369 view = (*it)->CreateDetailedView(login_status);
370 break;
371 case BUBBLE_TYPE_NOTIFICATION:
372 view = (*it)->CreateNotificationView(login_status);
373 break;
374 }
375 if (view)
376 bubble_view_->AddChildView(new TrayPopupItemContainer(view));
377 }
378 377
379 DCHECK(bubble_widget_ == NULL); 378 DCHECK(bubble_widget_ == NULL);
380 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); 379 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_);
381 380
382 // Must occur after call to CreateBubble() 381 // Must occur after call to CreateBubble()
383 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); 382 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
384 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); 383 bubble_widget_->non_client_view()->frame_view()->set_background(NULL);
385 SystemTrayBubbleBorder::ArrowType arrow_type; 384 SystemTrayBubbleBorder::ArrowType arrow_type;
386 if (anchor_type_ == ANCHOR_TYPE_TRAY) 385 if (anchor_type_ == ANCHOR_TYPE_TRAY)
387 arrow_type = SystemTrayBubbleBorder::ARROW_TYPE_BOTTOM; 386 arrow_type = SystemTrayBubbleBorder::ARROW_TYPE_BOTTOM;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 void SystemTrayBubble::RestartAutoCloseTimer() { 462 void SystemTrayBubble::RestartAutoCloseTimer() {
464 if (autoclose_delay_) 463 if (autoclose_delay_)
465 StartAutoCloseTimer(autoclose_delay_); 464 StartAutoCloseTimer(autoclose_delay_);
466 } 465 }
467 466
468 void SystemTrayBubble::Close() { 467 void SystemTrayBubble::Close() {
469 if (bubble_widget_) 468 if (bubble_widget_)
470 bubble_widget_->Close(); 469 bubble_widget_->Close();
471 } 470 }
472 471
472 void SystemTrayBubble::CreateItemViews(user::LoginStatus login_status) {
473 for (std::vector<ash::SystemTrayItem*>::iterator it = items_.begin();
474 it != items_.end();
475 ++it) {
476 views::View* view = NULL;
477 switch (bubble_type_) {
478 case BUBBLE_TYPE_DEFAULT:
479 view = (*it)->CreateDefaultView(login_status);
480 break;
481 case BUBBLE_TYPE_DETAILED:
482 view = (*it)->CreateDetailedView(login_status);
483 break;
484 case BUBBLE_TYPE_NOTIFICATION:
485 view = (*it)->CreateNotificationView(login_status);
486 break;
487 }
488 if (view)
489 bubble_view_->AddChildView(new TrayPopupItemContainer(view));
490 }
491 }
492
473 base::EventStatus SystemTrayBubble::WillProcessEvent( 493 base::EventStatus SystemTrayBubble::WillProcessEvent(
474 const base::NativeEvent& event) { 494 const base::NativeEvent& event) {
475 // Check if the user clicked outside of the bubble and close it if they did. 495 // Check if the user clicked outside of the bubble and close it if they did.
476 if (bubble_type_ != BUBBLE_TYPE_NOTIFICATION && 496 if (bubble_type_ != BUBBLE_TYPE_NOTIFICATION &&
477 ui::EventTypeFromNative(event) == ui::ET_MOUSE_PRESSED) { 497 ui::EventTypeFromNative(event) == ui::ET_MOUSE_PRESSED) {
478 gfx::Point cursor_in_view = ui::EventLocationFromNative(event); 498 gfx::Point cursor_in_view = ui::EventLocationFromNative(event);
479 views::View::ConvertPointFromScreen(bubble_view_, &cursor_in_view); 499 views::View::ConvertPointFromScreen(bubble_view_, &cursor_in_view);
480 if (!bubble_view_->HitTest(cursor_in_view)) { 500 if (!bubble_view_->HitTest(cursor_in_view)) {
481 bubble_widget_->Close(); 501 bubble_widget_->Close();
482 } 502 }
(...skipping 14 matching lines...) Expand all
497 void SystemTrayBubble::OnWidgetVisibilityChanged(views::Widget* widget, 517 void SystemTrayBubble::OnWidgetVisibilityChanged(views::Widget* widget,
498 bool visible) { 518 bool visible) {
499 if (!visible) 519 if (!visible)
500 MessageLoopForUI::current()->RemoveObserver(this); 520 MessageLoopForUI::current()->RemoveObserver(this);
501 else 521 else
502 MessageLoopForUI::current()->AddObserver(this); 522 MessageLoopForUI::current()->AddObserver(this);
503 } 523 }
504 524
505 } // namespace internal 525 } // namespace internal
506 } // namespace ash 526 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/system_tray_bubble.h ('k') | ash/system/tray/system_tray_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698