| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/status_bubble_mac.h" | 5 #include "chrome/browser/ui/cocoa/status_bubble_mac.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 170 } |
| 171 | 171 |
| 172 void StatusBubbleMac::SetStatus(const base::string16& status) { | 172 void StatusBubbleMac::SetStatus(const base::string16& status) { |
| 173 SetText(status, false); | 173 SetText(status, false); |
| 174 } | 174 } |
| 175 | 175 |
| 176 void StatusBubbleMac::SetURL(const GURL& url, const std::string& languages) { | 176 void StatusBubbleMac::SetURL(const GURL& url, const std::string& languages) { |
| 177 url_ = url; | 177 url_ = url; |
| 178 languages_ = languages; | 178 languages_ = languages; |
| 179 | 179 |
| 180 NSRect frame = [window_ frame]; | 180 CGFloat bubble_width = NSWidth([window_ frame]); |
| 181 | 181 |
| 182 // Reset frame size when bubble is hidden. | 182 // Reset frame size when bubble is hidden. |
| 183 if (state_ == kBubbleHidden) { | 183 if (state_ == kBubbleHidden) { |
| 184 is_expanded_ = false; | 184 is_expanded_ = false; |
| 185 frame.size.width = NSWidth(CalculateWindowFrame(/*expand=*/false)); | 185 NSRect frame = [window_ frame]; |
| 186 frame.size = ui::kWindowSizeDeterminedLater.size; |
| 186 [window_ setFrame:frame display:NO]; | 187 [window_ setFrame:frame display:NO]; |
| 188 bubble_width = NSWidth(CalculateWindowFrame(/*expand=*/false)); |
| 187 } | 189 } |
| 188 | 190 |
| 189 int text_width = static_cast<int>(NSWidth(frame) - | 191 int text_width = static_cast<int>(bubble_width - |
| 190 kBubbleViewTextPositionX - | 192 kBubbleViewTextPositionX - |
| 191 kTextPadding); | 193 kTextPadding); |
| 192 | 194 |
| 193 // Scale from view to window coordinates before eliding URL string. | 195 // Scale from view to window coordinates before eliding URL string. |
| 194 NSSize scaled_width = NSMakeSize(text_width, 0); | 196 NSSize scaled_width = NSMakeSize(text_width, 0); |
| 195 scaled_width = [[parent_ contentView] convertSize:scaled_width fromView:nil]; | 197 scaled_width = [[parent_ contentView] convertSize:scaled_width fromView:nil]; |
| 196 text_width = static_cast<int>(scaled_width.width); | 198 text_width = static_cast<int>(scaled_width.width); |
| 197 NSFont* font = [[window_ contentView] font]; | 199 NSFont* font = [[window_ contentView] font]; |
| 198 gfx::FontList font_list_chr( | 200 gfx::FontList font_list_chr( |
| 199 gfx::Font(base::SysNSStringToUTF8([font fontName]), [font pointSize])); | 201 gfx::Font(base::SysNSStringToUTF8([font fontName]), [font pointSize])); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 255 |
| 254 bool show = true; | 256 bool show = true; |
| 255 if ([*main length] > 0) | 257 if ([*main length] > 0) |
| 256 [[window_ contentView] setContent:*main]; | 258 [[window_ contentView] setContent:*main]; |
| 257 else if ([*backup length] > 0) | 259 else if ([*backup length] > 0) |
| 258 [[window_ contentView] setContent:*backup]; | 260 [[window_ contentView] setContent:*backup]; |
| 259 else | 261 else |
| 260 show = false; | 262 show = false; |
| 261 | 263 |
| 262 if (show) { | 264 if (show) { |
| 265 // Call StartShowing() first to update the current bubble state before |
| 266 // calculating a new size. |
| 267 StartShowing(); |
| 263 UpdateSizeAndPosition(); | 268 UpdateSizeAndPosition(); |
| 264 StartShowing(); | |
| 265 } else { | 269 } else { |
| 266 StartHiding(); | 270 StartHiding(); |
| 267 } | 271 } |
| 268 } | 272 } |
| 269 | 273 |
| 270 void StatusBubbleMac::Hide() { | 274 void StatusBubbleMac::Hide() { |
| 271 CancelTimer(); | 275 CancelTimer(); |
| 272 CancelExpandTimer(); | 276 CancelExpandTimer(); |
| 273 is_expanded_ = false; | 277 is_expanded_ = false; |
| 274 | 278 |
| 275 bool fade_out = false; | 279 bool fade_out = false; |
| 276 if (state_ == kBubbleHidingFadeOut || state_ == kBubbleShowingFadeIn) { | 280 if (state_ == kBubbleHidingFadeOut || state_ == kBubbleShowingFadeIn) { |
| 277 SetState(kBubbleHidingFadeOut); | 281 SetState(kBubbleHidingFadeOut); |
| 278 | 282 |
| 279 if (!immediate_) { | 283 if (!immediate_) { |
| 280 // An animation is in progress. Cancel it by starting a new animation. | 284 // An animation is in progress. Cancel it by starting a new animation. |
| 281 // Use kMinimumTimeInterval to set the opacity as rapidly as possible. | 285 // Use kMinimumTimeInterval to set the opacity as rapidly as possible. |
| 282 fade_out = true; | 286 fade_out = true; |
| 283 AnimateWindowAlpha(0.0, kMinimumTimeInterval); | 287 AnimateWindowAlpha(0.0, kMinimumTimeInterval); |
| 284 } | 288 } |
| 285 } | 289 } |
| 286 | 290 |
| 291 NSRect frame = CalculateWindowFrame(/*expand=*/false); |
| 287 if (!fade_out) { | 292 if (!fade_out) { |
| 288 // No animation is in progress, so the opacity can be set directly. | 293 // No animation is in progress, so the opacity can be set directly. |
| 289 [window_ setAlphaValue:0.0]; | 294 [window_ setAlphaValue:0.0]; |
| 290 SetState(kBubbleHidden); | 295 SetState(kBubbleHidden); |
| 296 frame.size = ui::kWindowSizeDeterminedLater.size; |
| 291 } | 297 } |
| 292 | 298 |
| 293 // Stop any width animation and reset the bubble size. | 299 // Stop any width animation and reset the bubble size. |
| 294 if (!immediate_) { | 300 if (!immediate_) { |
| 295 [NSAnimationContext beginGrouping]; | 301 [NSAnimationContext beginGrouping]; |
| 296 [[NSAnimationContext currentContext] setDuration:kMinimumTimeInterval]; | 302 [[NSAnimationContext currentContext] setDuration:kMinimumTimeInterval]; |
| 297 [[window_ animator] setFrame:CalculateWindowFrame(/*expand=*/false) | 303 [[window_ animator] setFrame:frame display:NO]; |
| 298 display:NO]; | |
| 299 [NSAnimationContext endGrouping]; | 304 [NSAnimationContext endGrouping]; |
| 300 } else { | 305 } else { |
| 301 [window_ setFrame:CalculateWindowFrame(/*expand=*/false) display:NO]; | 306 [window_ setFrame:frame display:NO]; |
| 302 } | 307 } |
| 303 | 308 |
| 304 [status_text_ release]; | 309 [status_text_ release]; |
| 305 status_text_ = nil; | 310 status_text_ = nil; |
| 306 [url_text_ release]; | 311 [url_text_ release]; |
| 307 url_text_ = nil; | 312 url_text_ = nil; |
| 308 } | 313 } |
| 309 | 314 |
| 310 void StatusBubbleMac::SetFrameAvoidingMouse( | 315 void StatusBubbleMac::SetFrameAvoidingMouse( |
| 311 NSRect window_frame, const gfx::Point& mouse_pos) { | 316 NSRect window_frame, const gfx::Point& mouse_pos) { |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 [NSAnimationContext beginGrouping]; | 715 [NSAnimationContext beginGrouping]; |
| 711 [[NSAnimationContext currentContext] setDuration:kExpansionDurationSeconds]; | 716 [[NSAnimationContext currentContext] setDuration:kExpansionDurationSeconds]; |
| 712 [[window_ animator] setFrame:actual_window_frame display:YES]; | 717 [[window_ animator] setFrame:actual_window_frame display:YES]; |
| 713 [NSAnimationContext endGrouping]; | 718 [NSAnimationContext endGrouping]; |
| 714 } | 719 } |
| 715 | 720 |
| 716 void StatusBubbleMac::UpdateSizeAndPosition() { | 721 void StatusBubbleMac::UpdateSizeAndPosition() { |
| 717 if (!window_) | 722 if (!window_) |
| 718 return; | 723 return; |
| 719 | 724 |
| 725 // Hidden bubbles always have size equal to ui::kWindowSizeDeterminedLater. |
| 726 if (state_ == kBubbleHidden) { |
| 727 NSRect frame = [window_ frame]; |
| 728 frame.size = ui::kWindowSizeDeterminedLater.size; |
| 729 [window_ setFrame:frame display:YES]; |
| 730 return; |
| 731 } |
| 732 |
| 720 SetFrameAvoidingMouse(CalculateWindowFrame(/*expand=*/false), | 733 SetFrameAvoidingMouse(CalculateWindowFrame(/*expand=*/false), |
| 721 GetMouseLocation()); | 734 GetMouseLocation()); |
| 722 } | 735 } |
| 723 | 736 |
| 724 void StatusBubbleMac::SwitchParentWindow(NSWindow* parent) { | 737 void StatusBubbleMac::SwitchParentWindow(NSWindow* parent) { |
| 725 DCHECK(parent); | 738 DCHECK(parent); |
| 726 DCHECK(is_attached()); | 739 DCHECK(is_attached()); |
| 727 | 740 |
| 728 Detach(); | 741 Detach(); |
| 729 parent_ = parent; | 742 parent_ = parent; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 } | 788 } |
| 776 | 789 |
| 777 // Round the top corners when the bubble is below the parent window. | 790 // Round the top corners when the bubble is below the parent window. |
| 778 if (NSMinY(window_frame) < NSMinY(parent_frame)) { | 791 if (NSMinY(window_frame) < NSMinY(parent_frame)) { |
| 779 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; | 792 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; |
| 780 } | 793 } |
| 781 } | 794 } |
| 782 | 795 |
| 783 return corner_flags; | 796 return corner_flags; |
| 784 } | 797 } |
| OLD | NEW |