Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "chrome/browser/ui/cocoa/notifications/balloon_view_bridge.h" | 9 #include "chrome/browser/ui/cocoa/notifications/balloon_view_bridge.h" |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 } | 28 } |
| 29 | 29 |
| 30 int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const { | 30 int BalloonCollectionImpl::Layout::HorizontalEdgeMargin() const { |
| 31 return 5; | 31 return 5; |
| 32 } | 32 } |
| 33 | 33 |
| 34 int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const { | 34 int BalloonCollectionImpl::Layout::VerticalEdgeMargin() const { |
| 35 return 0; | 35 return 0; |
| 36 } | 36 } |
| 37 | 37 |
| 38 gfx::Point BalloonCollectionImpl::Layout::GetLayoutOrigin() const { | |
|
jennb
2011/11/10 19:17:13
Comments in the code here make the code hard to re
jianli
2011/11/11 00:38:30
Done.
| |
| 39 const int kVerticalSpacingBetweenBalloonAndPanel = 5; | |
| 40 int x = 0; | |
| 41 int y = 0; | |
| 42 switch (placement_) { | |
| 43 case VERTICALLY_FROM_TOP_LEFT: { | |
| 44 x = work_area_.x() + HorizontalEdgeMargin(); | |
| 45 // For this placement (this corresponds to lower-right alignment due to | |
| 46 // that Mac uses a vertically reversed screen orientation), balloon needs | |
| 47 // to stay on top of left-most panels to avoid overlapping. | |
| 48 int offset = bottom_left_offset_to_move_above_panels_; | |
| 49 // Ensure that we have some sort of margin between the 1st balloon and the | |
| 50 // panel beneath it even the vertical edge margin is set to 0 on Mac. | |
| 51 if (offset && !VerticalEdgeMargin()) | |
| 52 offset += kVerticalSpacingBetweenBalloonAndPanel; | |
| 53 y = work_area_.y() + VerticalEdgeMargin() + offset; | |
| 54 break; | |
| 55 } | |
| 56 case VERTICALLY_FROM_TOP_RIGHT: { | |
| 57 x = work_area_.right() - HorizontalEdgeMargin(); | |
| 58 // For this placement (this corresponds to lower-right alignment due to | |
| 59 // that Mac uses a vertically reversed screen orientation), balloon needs | |
| 60 // to stay on top of right-most panels to avoid overlapping. | |
| 61 int offset = bottom_right_offset_to_move_above_panels_; | |
| 62 // Ensure that we have some sort of margin between the 1st balloon and the | |
| 63 // panel beneath it even the vertical edge margin is set to 0 on Mac. | |
| 64 if (offset && !VerticalEdgeMargin()) | |
| 65 offset += kVerticalSpacingBetweenBalloonAndPanel; | |
| 66 y = work_area_.y() + VerticalEdgeMargin() + offset; | |
| 67 break; | |
| 68 } | |
| 69 case VERTICALLY_FROM_BOTTOM_LEFT: | |
| 70 x = work_area_.x() + HorizontalEdgeMargin(); | |
| 71 y = work_area_.bottom() - VerticalEdgeMargin(); | |
| 72 break; | |
| 73 case VERTICALLY_FROM_BOTTOM_RIGHT: | |
| 74 x = work_area_.right() - HorizontalEdgeMargin(); | |
| 75 y = work_area_.bottom() - VerticalEdgeMargin(); | |
| 76 break; | |
| 77 default: | |
| 78 NOTREACHED(); | |
| 79 break; | |
| 80 } | |
| 81 return gfx::Point(x, y); | |
| 82 } | |
| 83 | |
| 38 void BalloonCollectionImpl::PositionBalloons(bool reposition) { | 84 void BalloonCollectionImpl::PositionBalloons(bool reposition) { |
| 39 // Use an animation context so that all the balloons animate together. | 85 // Use an animation context so that all the balloons animate together. |
| 40 [NSAnimationContext beginGrouping]; | 86 [NSAnimationContext beginGrouping]; |
| 41 [[NSAnimationContext currentContext] setDuration:0.1f]; | 87 [[NSAnimationContext currentContext] setDuration:0.1f]; |
| 42 PositionBalloonsInternal(reposition); | 88 PositionBalloonsInternal(reposition); |
| 43 [NSAnimationContext endGrouping]; | 89 [NSAnimationContext endGrouping]; |
| 44 } | 90 } |
| 45 | 91 |
| 46 void BalloonCollectionImpl::SetPositionPreference( | 92 void BalloonCollectionImpl::SetPositionPreference( |
| 47 PositionPreference position) { | 93 PositionPreference position) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 61 else | 107 else |
| 62 NOTREACHED(); | 108 NOTREACHED(); |
| 63 | 109 |
| 64 PositionBalloons(true); | 110 PositionBalloons(true); |
| 65 } | 111 } |
| 66 | 112 |
| 67 // static | 113 // static |
| 68 BalloonCollection* BalloonCollection::Create() { | 114 BalloonCollection* BalloonCollection::Create() { |
| 69 return new BalloonCollectionImpl(); | 115 return new BalloonCollectionImpl(); |
| 70 } | 116 } |
| OLD | NEW |