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

Side by Side Diff: chrome/browser/notifications/balloon_collection_impl.cc

Issue 8872044: Add test cases for panel overflow handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Final patch to land Created 9 years 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 | « no previous file | chrome/browser/ui/panels/base_panel_browser_test.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) 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/notifications/balloon_collection_impl.h" 5 #include "chrome/browser/notifications/balloon_collection_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "chrome/browser/notifications/balloon.h" 10 #include "chrome/browser/notifications/balloon.h"
11 #include "chrome/browser/notifications/balloon_host.h" 11 #include "chrome/browser/notifications/balloon_host.h"
12 #include "chrome/browser/notifications/notification.h" 12 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/panels/panel.h" 14 #include "chrome/browser/ui/panels/panel.h"
15 #include "chrome/browser/ui/panels/panel_manager.h" 15 #include "chrome/browser/ui/panels/panel_manager.h"
16 #include "chrome/browser/ui/panels/panel_strip.h"
16 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
17 #include "content/public/browser/notification_registrar.h" 18 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
19 #include "ui/gfx/rect.h" 20 #include "ui/gfx/rect.h"
20 #include "ui/gfx/screen.h" 21 #include "ui/gfx/screen.h"
21 #include "ui/gfx/size.h" 22 #include "ui/gfx/size.h"
22 23
23 namespace { 24 namespace {
24 25
25 // Portion of the screen allotted for notifications. When notification balloons 26 // Portion of the screen allotted for notifications. When notification balloons
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 // restrict to the min & max sizes 393 // restrict to the min & max sizes
393 return gfx::Size( 394 return gfx::Size(
394 std::max(min_balloon_width(), 395 std::max(min_balloon_width(),
395 std::min(max_balloon_width(), size.width())), 396 std::min(max_balloon_width(), size.width())),
396 std::max(min_balloon_height(), 397 std::max(min_balloon_height(),
397 std::min(max_balloon_height(), size.height()))); 398 std::min(max_balloon_height(), size.height())));
398 } 399 }
399 400
400 bool BalloonCollectionImpl::Layout::ComputeOffsetToMoveAbovePanels( 401 bool BalloonCollectionImpl::Layout::ComputeOffsetToMoveAbovePanels(
401 const gfx::Rect& panel_bounds) { 402 const gfx::Rect& panel_bounds) {
402 const PanelManager::Panels& panels = PanelManager::GetInstance()->panels(); 403 const PanelStrip::Panels& panels =
404 PanelManager::GetInstance()->panel_strip()->panels();
403 int offset_to_move_above_panels = 0; 405 int offset_to_move_above_panels = 0;
404 406
405 // The offset is the maximum height of panels that could overlap with the 407 // The offset is the maximum height of panels that could overlap with the
406 // balloons. 408 // balloons.
407 if (NeedToMoveAboveLeftSidePanels()) { 409 if (NeedToMoveAboveLeftSidePanels()) {
408 // If the affecting panel does not lie in the balloon area, no need to 410 // If the affecting panel does not lie in the balloon area, no need to
409 // update the offset. 411 // update the offset.
410 if (!panel_bounds.IsEmpty() && 412 if (!panel_bounds.IsEmpty() &&
411 (panel_bounds.right() <= work_area_.x() || 413 (panel_bounds.right() <= work_area_.x() ||
412 panel_bounds.x() >= work_area_.x() + max_balloon_width())) { 414 panel_bounds.x() >= work_area_.x() + max_balloon_width())) {
413 return false; 415 return false;
414 } 416 }
415 417
416 for (PanelManager::Panels::const_reverse_iterator iter = panels.rbegin(); 418 for (PanelStrip::Panels::const_reverse_iterator iter = panels.rbegin();
417 iter != panels.rend(); ++iter) { 419 iter != panels.rend(); ++iter) {
418 // No need to check panels beyond the area occupied by the balloons. 420 // No need to check panels beyond the area occupied by the balloons.
419 if ((*iter)->GetBounds().x() >= work_area_.x() + max_balloon_width()) 421 if ((*iter)->GetBounds().x() >= work_area_.x() + max_balloon_width())
420 break; 422 break;
421 423
422 int current_height = (*iter)->GetBounds().height(); 424 int current_height = (*iter)->GetBounds().height();
423 if (current_height > offset_to_move_above_panels) 425 if (current_height > offset_to_move_above_panels)
424 offset_to_move_above_panels = current_height; 426 offset_to_move_above_panels = current_height;
425 } 427 }
426 } else if (NeedToMoveAboveRightSidePanels()) { 428 } else if (NeedToMoveAboveRightSidePanels()) {
427 // If the affecting panel does not lie in the balloon area, no need to 429 // If the affecting panel does not lie in the balloon area, no need to
428 // update the offset. 430 // update the offset.
429 if (!panel_bounds.IsEmpty() && 431 if (!panel_bounds.IsEmpty() &&
430 (panel_bounds.right() <= work_area_.right() - max_balloon_width() || 432 (panel_bounds.right() <= work_area_.right() - max_balloon_width() ||
431 panel_bounds.x() >= work_area_.right())) { 433 panel_bounds.x() >= work_area_.right())) {
432 return false; 434 return false;
433 } 435 }
434 436
435 for (PanelManager::Panels::const_iterator iter = panels.begin(); 437 for (PanelStrip::Panels::const_iterator iter = panels.begin();
436 iter != panels.end(); ++iter) { 438 iter != panels.end(); ++iter) {
437 // No need to check panels beyond the area occupied by the balloons. 439 // No need to check panels beyond the area occupied by the balloons.
438 if ((*iter)->GetBounds().right() <= 440 if ((*iter)->GetBounds().right() <=
439 work_area_.right() - max_balloon_width()) 441 work_area_.right() - max_balloon_width())
440 break; 442 break;
441 443
442 int current_height = (*iter)->GetBounds().height(); 444 int current_height = (*iter)->GetBounds().height();
443 if (current_height > offset_to_move_above_panels) 445 if (current_height > offset_to_move_above_panels)
444 offset_to_move_above_panels = current_height; 446 offset_to_move_above_panels = current_height;
445 } 447 }
(...skipping 22 matching lines...) Expand all
468 gfx::Rect new_work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); 470 gfx::Rect new_work_area = gfx::Screen::GetPrimaryMonitorWorkArea();
469 #endif 471 #endif
470 if (!work_area_.Equals(new_work_area)) { 472 if (!work_area_.Equals(new_work_area)) {
471 work_area_.SetRect(new_work_area.x(), new_work_area.y(), 473 work_area_.SetRect(new_work_area.x(), new_work_area.y(),
472 new_work_area.width(), new_work_area.height()); 474 new_work_area.width(), new_work_area.height());
473 changed = true; 475 changed = true;
474 } 476 }
475 477
476 return changed; 478 return changed;
477 } 479 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/panels/base_panel_browser_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698