| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "app/gfx/text_elider.h" | 9 #include "app/gfx/text_elider.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 218 |
| 219 // Adjust the position to sit on top of download and extension shelves. | 219 // Adjust the position to sit on top of download and extension shelves. |
| 220 // |delegate_| can be nil during unit tests. | 220 // |delegate_| can be nil during unit tests. |
| 221 if ([delegate_ respondsToSelector:@selector(verticalOffsetForStatusBubble)]) | 221 if ([delegate_ respondsToSelector:@selector(verticalOffsetForStatusBubble)]) |
| 222 window_frame.origin.y += [delegate_ verticalOffsetForStatusBubble]; | 222 window_frame.origin.y += [delegate_ verticalOffsetForStatusBubble]; |
| 223 | 223 |
| 224 // Get the cursor position relative to the popup. | 224 // Get the cursor position relative to the popup. |
| 225 cursor_location.x -= NSMaxX(window_frame); | 225 cursor_location.x -= NSMaxX(window_frame); |
| 226 cursor_location.y -= NSMaxY(window_frame); | 226 cursor_location.y -= NSMaxY(window_frame); |
| 227 | 227 |
| 228 bool isShelfVisible = [delegate_ verticalOffsetForStatusBubble] > 0; |
| 229 |
| 228 // If the mouse is in a position where we think it would move the | 230 // If the mouse is in a position where we think it would move the |
| 229 // status bubble, figure out where and how the bubble should be moved. | 231 // status bubble, figure out where and how the bubble should be moved. |
| 230 if (cursor_location.y < kMousePadding && | 232 if (cursor_location.y < kMousePadding && |
| 231 cursor_location.x < kMousePadding) { | 233 cursor_location.x < kMousePadding) { |
| 232 int offset = kMousePadding - cursor_location.y; | 234 int offset = kMousePadding - cursor_location.y; |
| 233 | 235 |
| 234 // Make the movement non-linear. | 236 // Make the movement non-linear. |
| 235 offset = offset * offset / kMousePadding; | 237 offset = offset * offset / kMousePadding; |
| 236 | 238 |
| 237 // When the mouse is entering from the right, we want the offset to be | 239 // When the mouse is entering from the right, we want the offset to be |
| 238 // scaled by how horizontally far away the cursor is from the bubble. | 240 // scaled by how horizontally far away the cursor is from the bubble. |
| 239 if (cursor_location.x > 0) { | 241 if (cursor_location.x > 0) { |
| 240 offset = offset * ((kMousePadding - cursor_location.x) / kMousePadding); | 242 offset = offset * ((kMousePadding - cursor_location.x) / kMousePadding); |
| 241 } | 243 } |
| 242 | 244 |
| 243 // Cap the offset and change the visual presentation of the bubble | 245 bool isOnScreen = true; |
| 244 // depending on where it ends up (so that rounded corners square off | 246 NSScreen* screen = [window_ screen]; |
| 245 // and mate to the edges of the tab content). | 247 if (screen && |
| 246 if (offset >= NSHeight(window_frame)) { | 248 NSMinY([screen visibleFrame]) > NSMinY(window_frame) - offset) { |
| 247 offset = NSHeight(window_frame); | 249 isOnScreen = false; |
| 248 [[window_ contentView] setCornerFlags: | |
| 249 kRoundedBottomLeftCorner | kRoundedBottomRightCorner]; | |
| 250 } else if (offset > 0) { | |
| 251 [[window_ contentView] setCornerFlags: | |
| 252 kRoundedTopRightCorner | kRoundedBottomLeftCorner | | |
| 253 kRoundedBottomRightCorner]; | |
| 254 } else { | |
| 255 [[window_ contentView] setCornerFlags:kRoundedTopRightCorner]; | |
| 256 } | 250 } |
| 257 | 251 |
| 258 window_frame.origin.y -= offset; | 252 if (isOnScreen && !isShelfVisible) { |
| 253 // Cap the offset and change the visual presentation of the bubble |
| 254 // depending on where it ends up (so that rounded corners square off |
| 255 // and mate to the edges of the tab content). |
| 256 if (offset >= NSHeight(window_frame)) { |
| 257 offset = NSHeight(window_frame); |
| 258 [[window_ contentView] setCornerFlags: |
| 259 kRoundedBottomLeftCorner | kRoundedBottomRightCorner]; |
| 260 } else if (offset > 0) { |
| 261 [[window_ contentView] setCornerFlags: |
| 262 kRoundedTopRightCorner | kRoundedBottomLeftCorner | |
| 263 kRoundedBottomRightCorner]; |
| 264 } else { |
| 265 [[window_ contentView] setCornerFlags:kRoundedTopRightCorner]; |
| 266 } |
| 267 window_frame.origin.y -= offset; |
| 268 } else { |
| 269 // The bubble will obscure the download shelf. Move the bubble to the |
| 270 // right and reset Y offset_ to zero. |
| 271 [[window_ contentView] setCornerFlags:kRoundedTopLeftCorner]; |
| 272 |
| 273 // Subtract border width + bubble width. |
| 274 window_frame.origin.x += NSWidth([parent_ frame]) - NSWidth(window_frame); |
| 275 } |
| 259 } else { | 276 } else { |
| 260 [[window_ contentView] setCornerFlags:kRoundedTopRightCorner]; | 277 [[window_ contentView] setCornerFlags:kRoundedTopRightCorner]; |
| 261 } | 278 } |
| 262 | 279 |
| 263 [window_ setFrame:window_frame display:YES]; | 280 [window_ setFrame:window_frame display:YES]; |
| 264 } | 281 } |
| 265 | 282 |
| 266 void StatusBubbleMac::UpdateDownloadShelfVisibility(bool visible) { | 283 void StatusBubbleMac::UpdateDownloadShelfVisibility(bool visible) { |
| 267 } | 284 } |
| 268 | 285 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 } | 502 } |
| 486 | 503 |
| 487 NSRect StatusBubbleMac::CalculateWindowFrame() { | 504 NSRect StatusBubbleMac::CalculateWindowFrame() { |
| 488 DCHECK(parent_); | 505 DCHECK(parent_); |
| 489 | 506 |
| 490 NSRect rect = [parent_ frame]; | 507 NSRect rect = [parent_ frame]; |
| 491 rect.size.height = kWindowHeight; | 508 rect.size.height = kWindowHeight; |
| 492 rect.size.width = static_cast<int>(kWindowWidthPercent * rect.size.width); | 509 rect.size.width = static_cast<int>(kWindowWidthPercent * rect.size.width); |
| 493 return rect; | 510 return rect; |
| 494 } | 511 } |
| OLD | NEW |