| 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/cocoa/status_bubble_mac.h" | 5 #include "chrome/browser/cocoa/status_bubble_mac.h" |
| 6 | 6 |
| 7 #include "app/gfx/text_elider.h" | 7 #include "app/gfx/text_elider.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #import "chrome/browser/cocoa/bubble_view.h" | 10 #import "chrome/browser/cocoa/bubble_view.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 if (!window_) | 120 if (!window_) |
| 121 return; | 121 return; |
| 122 | 122 |
| 123 NSPoint cursor_location = [NSEvent mouseLocation]; | 123 NSPoint cursor_location = [NSEvent mouseLocation]; |
| 124 --cursor_location.y; // docs say the y coord starts at 1 not 0; don't ask why | 124 --cursor_location.y; // docs say the y coord starts at 1 not 0; don't ask why |
| 125 | 125 |
| 126 // Get the normal position of the frame. | 126 // Get the normal position of the frame. |
| 127 NSRect window_frame = [window_ frame]; | 127 NSRect window_frame = [window_ frame]; |
| 128 window_frame.origin = [parent_ frame].origin; | 128 window_frame.origin = [parent_ frame].origin; |
| 129 | 129 |
| 130 // Adjust the position to sit on top of download shelf. |
| 131 // |delegate_| can be nil during unit tests. |
| 132 if (is_download_shelf_visible_) { |
| 133 if ([delegate_ respondsToSelector:@selector(verticalOffsetForStatusBubble)]) |
| 134 window_frame.origin.y += [delegate_ verticalOffsetForStatusBubble]; |
| 135 } |
| 136 |
| 130 // Get the cursor position relative to the popup. | 137 // Get the cursor position relative to the popup. |
| 131 cursor_location.x -= NSMaxX(window_frame); | 138 cursor_location.x -= NSMaxX(window_frame); |
| 132 cursor_location.y -= NSMaxY(window_frame); | 139 cursor_location.y -= NSMaxY(window_frame); |
| 133 | 140 |
| 134 // If the mouse is in a position where we think it would move the | 141 // If the mouse is in a position where we think it would move the |
| 135 // status bubble, figure out where and how the bubble should be moved. | 142 // status bubble, figure out where and how the bubble should be moved. |
| 136 if (cursor_location.y < kMousePadding && | 143 if (cursor_location.y < kMousePadding && |
| 137 cursor_location.x < kMousePadding) { | 144 cursor_location.x < kMousePadding) { |
| 138 int offset = kMousePadding - cursor_location.y; | 145 int offset = kMousePadding - cursor_location.y; |
| 139 | 146 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 161 [[window_ contentView] setCornerFlags:kRoundedTopRightCorner]; | 168 [[window_ contentView] setCornerFlags:kRoundedTopRightCorner]; |
| 162 } | 169 } |
| 163 | 170 |
| 164 offset_ = offset; | 171 offset_ = offset; |
| 165 window_frame.origin.y -= offset; | 172 window_frame.origin.y -= offset; |
| 166 } else { | 173 } else { |
| 167 offset_ = 0; | 174 offset_ = 0; |
| 168 [[window_ contentView] setCornerFlags:kRoundedTopRightCorner]; | 175 [[window_ contentView] setCornerFlags:kRoundedTopRightCorner]; |
| 169 } | 176 } |
| 170 | 177 |
| 171 // |delegate_| can be nil during unit tests. | |
| 172 if (is_download_shelf_visible_) { | |
| 173 if ([delegate_ respondsToSelector:@selector(verticalOffsetForStatusBubble)]) | |
| 174 window_frame.origin.y += [delegate_ verticalOffsetForStatusBubble]; | |
| 175 } | |
| 176 | |
| 177 [window_ setFrame:window_frame display:YES]; | 178 [window_ setFrame:window_frame display:YES]; |
| 178 } | 179 } |
| 179 | 180 |
| 180 void StatusBubbleMac::UpdateDownloadShelfVisibility(bool visible) { | 181 void StatusBubbleMac::UpdateDownloadShelfVisibility(bool visible) { |
| 181 is_download_shelf_visible_ = visible; | 182 is_download_shelf_visible_ = visible; |
| 182 } | 183 } |
| 183 | 184 |
| 184 void StatusBubbleMac::Create() { | 185 void StatusBubbleMac::Create() { |
| 185 if (window_) | 186 if (window_) |
| 186 return; | 187 return; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 [NSAnimationContext endGrouping]; | 224 [NSAnimationContext endGrouping]; |
| 224 } | 225 } |
| 225 | 226 |
| 226 void StatusBubbleMac::FadeOut() { | 227 void StatusBubbleMac::FadeOut() { |
| 227 [NSAnimationContext beginGrouping]; | 228 [NSAnimationContext beginGrouping]; |
| 228 [[NSAnimationContext currentContext] setDuration:kHideFadeDuration]; | 229 [[NSAnimationContext currentContext] setDuration:kHideFadeDuration]; |
| 229 [[window_ animator] setAlphaValue:0.0f]; | 230 [[window_ animator] setAlphaValue:0.0f]; |
| 230 [NSAnimationContext endGrouping]; | 231 [NSAnimationContext endGrouping]; |
| 231 } | 232 } |
| 232 | 233 |
| OLD | NEW |