| 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 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 if (!window_) | 142 if (!window_) |
| 143 return; | 143 return; |
| 144 | 144 |
| 145 NSPoint cursor_location = [NSEvent mouseLocation]; | 145 NSPoint cursor_location = [NSEvent mouseLocation]; |
| 146 --cursor_location.y; // docs say the y coord starts at 1 not 0; don't ask why | 146 --cursor_location.y; // docs say the y coord starts at 1 not 0; don't ask why |
| 147 | 147 |
| 148 // Get the normal position of the frame. | 148 // Get the normal position of the frame. |
| 149 NSRect window_frame = [window_ frame]; | 149 NSRect window_frame = [window_ frame]; |
| 150 window_frame.origin = [parent_ frame].origin; | 150 window_frame.origin = [parent_ frame].origin; |
| 151 | 151 |
| 152 // Adjust the position to sit on top of download shelf. |
| 153 // |delegate_| can be nil during unit tests. |
| 154 if (is_download_shelf_visible_) { |
| 155 if ([delegate_ respondsToSelector:@selector(verticalOffsetForStatusBubble)]) |
| 156 window_frame.origin.y += [delegate_ verticalOffsetForStatusBubble]; |
| 157 } |
| 158 |
| 152 // Get the cursor position relative to the popup. | 159 // Get the cursor position relative to the popup. |
| 153 cursor_location.x -= NSMaxX(window_frame); | 160 cursor_location.x -= NSMaxX(window_frame); |
| 154 cursor_location.y -= NSMaxY(window_frame); | 161 cursor_location.y -= NSMaxY(window_frame); |
| 155 | 162 |
| 156 // If the mouse is in a position where we think it would move the | 163 // If the mouse is in a position where we think it would move the |
| 157 // status bubble, figure out where and how the bubble should be moved. | 164 // status bubble, figure out where and how the bubble should be moved. |
| 158 if (cursor_location.y < kMousePadding && | 165 if (cursor_location.y < kMousePadding && |
| 159 cursor_location.x < kMousePadding) { | 166 cursor_location.x < kMousePadding) { |
| 160 int offset = kMousePadding - cursor_location.y; | 167 int offset = kMousePadding - cursor_location.y; |
| 161 | 168 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 180 [[window_ contentView] setStyle:STYLE_STANDARD]; | 187 [[window_ contentView] setStyle:STYLE_STANDARD]; |
| 181 } | 188 } |
| 182 | 189 |
| 183 offset_ = offset; | 190 offset_ = offset; |
| 184 window_frame.origin.y -= offset; | 191 window_frame.origin.y -= offset; |
| 185 } else { | 192 } else { |
| 186 offset_ = 0; | 193 offset_ = 0; |
| 187 [[window_ contentView] setStyle:STYLE_STANDARD]; | 194 [[window_ contentView] setStyle:STYLE_STANDARD]; |
| 188 } | 195 } |
| 189 | 196 |
| 190 // |delegate_| can be nil during unit tests. | |
| 191 if (is_download_shelf_visible_) { | |
| 192 if ([delegate_ respondsToSelector:@selector(verticalOffsetForStatusBubble)]) | |
| 193 window_frame.origin.y += [delegate_ verticalOffsetForStatusBubble]; | |
| 194 } | |
| 195 | |
| 196 [window_ setFrame:window_frame display:YES]; | 197 [window_ setFrame:window_frame display:YES]; |
| 197 } | 198 } |
| 198 | 199 |
| 199 void StatusBubbleMac::UpdateDownloadShelfVisibility(bool visible) { | 200 void StatusBubbleMac::UpdateDownloadShelfVisibility(bool visible) { |
| 200 is_download_shelf_visible_ = visible; | 201 is_download_shelf_visible_ = visible; |
| 201 } | 202 } |
| 202 | 203 |
| 203 void StatusBubbleMac::Create() { | 204 void StatusBubbleMac::Create() { |
| 204 if (window_) | 205 if (window_) |
| 205 return; | 206 return; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 329 |
| 329 NSDictionary* textDict = [NSDictionary dictionaryWithObjectsAndKeys: | 330 NSDictionary* textDict = [NSDictionary dictionaryWithObjectsAndKeys: |
| 330 textFont, NSFontAttributeName, | 331 textFont, NSFontAttributeName, |
| 331 textShadow, NSShadowAttributeName, | 332 textShadow, NSShadowAttributeName, |
| 332 nil]; | 333 nil]; |
| 333 [content_ drawAtPoint:NSMakePoint(kTextPositionX, kTextPositionY) | 334 [content_ drawAtPoint:NSMakePoint(kTextPositionX, kTextPositionY) |
| 334 withAttributes:textDict]; | 335 withAttributes:textDict]; |
| 335 } | 336 } |
| 336 | 337 |
| 337 @end | 338 @end |
| OLD | NEW |