| 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 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 | 33 |
| 34 // TODO(avi): | 34 // TODO(avi): |
| 35 // - do display delay | 35 // - do display delay |
| 36 | 36 |
| 37 StatusBubbleMac::StatusBubbleMac(NSWindow* parent, id delegate) | 37 StatusBubbleMac::StatusBubbleMac(NSWindow* parent, id delegate) |
| 38 : parent_(parent), | 38 : parent_(parent), |
| 39 delegate_(delegate), | 39 delegate_(delegate), |
| 40 window_(nil), | 40 window_(nil), |
| 41 status_text_(nil), | 41 status_text_(nil), |
| 42 url_text_(nil), | 42 url_text_(nil) { |
| 43 is_download_shelf_visible_(false) { | |
| 44 } | 43 } |
| 45 | 44 |
| 46 StatusBubbleMac::~StatusBubbleMac() { | 45 StatusBubbleMac::~StatusBubbleMac() { |
| 47 Hide(); | 46 Hide(); |
| 48 } | 47 } |
| 49 | 48 |
| 50 void StatusBubbleMac::SetStatus(const std::wstring& status) { | 49 void StatusBubbleMac::SetStatus(const std::wstring& status) { |
| 51 Create(); | 50 Create(); |
| 52 | 51 |
| 53 NSString* status_ns = base::SysWideToNSString(status); | 52 NSString* status_ns = base::SysWideToNSString(status); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 if (!window_) | 119 if (!window_) |
| 121 return; | 120 return; |
| 122 | 121 |
| 123 NSPoint cursor_location = [NSEvent mouseLocation]; | 122 NSPoint cursor_location = [NSEvent mouseLocation]; |
| 124 --cursor_location.y; // docs say the y coord starts at 1 not 0; don't ask why | 123 --cursor_location.y; // docs say the y coord starts at 1 not 0; don't ask why |
| 125 | 124 |
| 126 // Get the normal position of the frame. | 125 // Get the normal position of the frame. |
| 127 NSRect window_frame = [window_ frame]; | 126 NSRect window_frame = [window_ frame]; |
| 128 window_frame.origin = [parent_ frame].origin; | 127 window_frame.origin = [parent_ frame].origin; |
| 129 | 128 |
| 130 // Adjust the position to sit on top of download shelf. | 129 // Adjust the position to sit on top of download and extension shelves. |
| 131 // |delegate_| can be nil during unit tests. | 130 // |delegate_| can be nil during unit tests. |
| 132 if (is_download_shelf_visible_) { | 131 if ([delegate_ respondsToSelector:@selector(verticalOffsetForStatusBubble)]) |
| 133 if ([delegate_ respondsToSelector:@selector(verticalOffsetForStatusBubble)]) | 132 window_frame.origin.y += [delegate_ verticalOffsetForStatusBubble]; |
| 134 window_frame.origin.y += [delegate_ verticalOffsetForStatusBubble]; | |
| 135 } | |
| 136 | 133 |
| 137 // Get the cursor position relative to the popup. | 134 // Get the cursor position relative to the popup. |
| 138 cursor_location.x -= NSMaxX(window_frame); | 135 cursor_location.x -= NSMaxX(window_frame); |
| 139 cursor_location.y -= NSMaxY(window_frame); | 136 cursor_location.y -= NSMaxY(window_frame); |
| 140 | 137 |
| 141 // If the mouse is in a position where we think it would move the | 138 // If the mouse is in a position where we think it would move the |
| 142 // status bubble, figure out where and how the bubble should be moved. | 139 // status bubble, figure out where and how the bubble should be moved. |
| 143 if (cursor_location.y < kMousePadding && | 140 if (cursor_location.y < kMousePadding && |
| 144 cursor_location.x < kMousePadding) { | 141 cursor_location.x < kMousePadding) { |
| 145 int offset = kMousePadding - cursor_location.y; | 142 int offset = kMousePadding - cursor_location.y; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 172 window_frame.origin.y -= offset; | 169 window_frame.origin.y -= offset; |
| 173 } else { | 170 } else { |
| 174 offset_ = 0; | 171 offset_ = 0; |
| 175 [[window_ contentView] setCornerFlags:kRoundedTopRightCorner]; | 172 [[window_ contentView] setCornerFlags:kRoundedTopRightCorner]; |
| 176 } | 173 } |
| 177 | 174 |
| 178 [window_ setFrame:window_frame display:YES]; | 175 [window_ setFrame:window_frame display:YES]; |
| 179 } | 176 } |
| 180 | 177 |
| 181 void StatusBubbleMac::UpdateDownloadShelfVisibility(bool visible) { | 178 void StatusBubbleMac::UpdateDownloadShelfVisibility(bool visible) { |
| 182 is_download_shelf_visible_ = visible; | |
| 183 } | 179 } |
| 184 | 180 |
| 185 void StatusBubbleMac::Create() { | 181 void StatusBubbleMac::Create() { |
| 186 if (window_) | 182 if (window_) |
| 187 return; | 183 return; |
| 188 | 184 |
| 189 NSRect rect = [parent_ frame]; | 185 NSRect rect = [parent_ frame]; |
| 190 rect.size.height = kWindowHeight; | 186 rect.size.height = kWindowHeight; |
| 191 rect.size.width = static_cast<int>(kWindowWidthPercent * rect.size.width); | 187 rect.size.width = static_cast<int>(kWindowWidthPercent * rect.size.width); |
| 192 // TODO(avi):fix this for RTL | 188 // TODO(avi):fix this for RTL |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 [NSAnimationContext endGrouping]; | 220 [NSAnimationContext endGrouping]; |
| 225 } | 221 } |
| 226 | 222 |
| 227 void StatusBubbleMac::FadeOut() { | 223 void StatusBubbleMac::FadeOut() { |
| 228 [NSAnimationContext beginGrouping]; | 224 [NSAnimationContext beginGrouping]; |
| 229 [[NSAnimationContext currentContext] setDuration:kHideFadeDuration]; | 225 [[NSAnimationContext currentContext] setDuration:kHideFadeDuration]; |
| 230 [[window_ animator] setAlphaValue:0.0f]; | 226 [[window_ animator] setAlphaValue:0.0f]; |
| 231 [NSAnimationContext endGrouping]; | 227 [NSAnimationContext endGrouping]; |
| 232 } | 228 } |
| 233 | 229 |
| OLD | NEW |