| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 [[[window_ animationForKey:kFadeAnimationKey] delegate] invalidate]; | 118 [[[window_ animationForKey:kFadeAnimationKey] delegate] invalidate]; |
| 119 Detach(); | 119 Detach(); |
| 120 [window_ release]; | 120 [window_ release]; |
| 121 window_ = nil; | 121 window_ = nil; |
| 122 } | 122 } |
| 123 | 123 |
| 124 void StatusBubbleMac::SetStatus(const string16& status) { | 124 void StatusBubbleMac::SetStatus(const string16& status) { |
| 125 SetText(status, false); | 125 SetText(status, false); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void StatusBubbleMac::SetURL(const GURL& url, const string16& languages) { | 128 void StatusBubbleMac::SetURL(const GURL& url, const std::string& languages) { |
| 129 url_ = url; | 129 url_ = url; |
| 130 languages_ = languages; | 130 languages_ = languages; |
| 131 | 131 |
| 132 NSRect frame = [window_ frame]; | 132 NSRect frame = [window_ frame]; |
| 133 | 133 |
| 134 // Reset frame size when bubble is hidden. | 134 // Reset frame size when bubble is hidden. |
| 135 if (state_ == kBubbleHidden) { | 135 if (state_ == kBubbleHidden) { |
| 136 is_expanded_ = false; | 136 is_expanded_ = false; |
| 137 frame.size.width = NSWidth(CalculateWindowFrame(/*expand=*/false)); | 137 frame.size.width = NSWidth(CalculateWindowFrame(/*expand=*/false)); |
| 138 [window_ setFrame:frame display:NO]; | 138 [window_ setFrame:frame display:NO]; |
| 139 } | 139 } |
| 140 | 140 |
| 141 int text_width = static_cast<int>(NSWidth(frame) - | 141 int text_width = static_cast<int>(NSWidth(frame) - |
| 142 kBubbleViewTextPositionX - | 142 kBubbleViewTextPositionX - |
| 143 kTextPadding); | 143 kTextPadding); |
| 144 | 144 |
| 145 // Scale from view to window coordinates before eliding URL string. | 145 // Scale from view to window coordinates before eliding URL string. |
| 146 NSSize scaled_width = NSMakeSize(text_width, 0); | 146 NSSize scaled_width = NSMakeSize(text_width, 0); |
| 147 scaled_width = [[parent_ contentView] convertSize:scaled_width fromView:nil]; | 147 scaled_width = [[parent_ contentView] convertSize:scaled_width fromView:nil]; |
| 148 text_width = static_cast<int>(scaled_width.width); | 148 text_width = static_cast<int>(scaled_width.width); |
| 149 NSFont* font = [[window_ contentView] font]; | 149 NSFont* font = [[window_ contentView] font]; |
| 150 gfx::Font font_chr(base::SysNSStringToUTF16([font fontName]), | 150 gfx::Font font_chr(base::SysNSStringToUTF16([font fontName]), |
| 151 [font pointSize]); | 151 [font pointSize]); |
| 152 | 152 |
| 153 string16 original_url_text = net::FormatUrl(url, UTF16ToUTF8(languages)); | 153 string16 original_url_text = net::FormatUrl(url, languages); |
| 154 string16 status = ui::ElideUrl(url, font_chr, text_width, | 154 string16 status = ui::ElideUrl(url, font_chr, text_width, languages); |
| 155 UTF16ToUTF8(languages)); | |
| 156 | 155 |
| 157 SetText(status, true); | 156 SetText(status, true); |
| 158 | 157 |
| 159 // In testing, don't use animation. When ExpandBubble is tested, it is | 158 // In testing, don't use animation. When ExpandBubble is tested, it is |
| 160 // called explicitly. | 159 // called explicitly. |
| 161 if (immediate_) | 160 if (immediate_) |
| 162 return; | 161 return; |
| 163 else | 162 else |
| 164 CancelExpandTimer(); | 163 CancelExpandTimer(); |
| 165 | 164 |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 // Calculate the width available for expanded and standard bubbles. | 599 // Calculate the width available for expanded and standard bubbles. |
| 601 NSRect window_frame = CalculateWindowFrame(/*expand=*/true); | 600 NSRect window_frame = CalculateWindowFrame(/*expand=*/true); |
| 602 CGFloat max_bubble_width = NSWidth(window_frame); | 601 CGFloat max_bubble_width = NSWidth(window_frame); |
| 603 CGFloat standard_bubble_width = | 602 CGFloat standard_bubble_width = |
| 604 NSWidth(CalculateWindowFrame(/*expand=*/false)); | 603 NSWidth(CalculateWindowFrame(/*expand=*/false)); |
| 605 | 604 |
| 606 // Generate the URL string that fits in the expanded bubble. | 605 // Generate the URL string that fits in the expanded bubble. |
| 607 NSFont* font = [[window_ contentView] font]; | 606 NSFont* font = [[window_ contentView] font]; |
| 608 gfx::Font font_chr(base::SysNSStringToUTF16([font fontName]), | 607 gfx::Font font_chr(base::SysNSStringToUTF16([font fontName]), |
| 609 [font pointSize]); | 608 [font pointSize]); |
| 610 string16 expanded_url = ui::ElideUrl(url_, font_chr, | 609 string16 expanded_url = ui::ElideUrl( |
| 611 max_bubble_width, UTF16ToUTF8(languages_)); | 610 url_, font_chr, max_bubble_width, languages_); |
| 612 | 611 |
| 613 // Scale width from gfx::Font in view coordinates to window coordinates. | 612 // Scale width from gfx::Font in view coordinates to window coordinates. |
| 614 int required_width_for_string = | 613 int required_width_for_string = |
| 615 font_chr.GetStringWidth(expanded_url) + | 614 font_chr.GetStringWidth(expanded_url) + |
| 616 kTextPadding * 2 + kBubbleViewTextPositionX; | 615 kTextPadding * 2 + kBubbleViewTextPositionX; |
| 617 NSSize scaled_width = NSMakeSize(required_width_for_string, 0); | 616 NSSize scaled_width = NSMakeSize(required_width_for_string, 0); |
| 618 scaled_width = [[parent_ contentView] convertSize:scaled_width toView:nil]; | 617 scaled_width = [[parent_ contentView] convertSize:scaled_width toView:nil]; |
| 619 required_width_for_string = scaled_width.width; | 618 required_width_for_string = scaled_width.width; |
| 620 | 619 |
| 621 // The expanded width must be at least as wide as the standard width, but no | 620 // The expanded width must be at least as wide as the standard width, but no |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 } | 724 } |
| 726 | 725 |
| 727 // Round the top corners when the bubble is below the parent window. | 726 // Round the top corners when the bubble is below the parent window. |
| 728 if (NSMinY(window_frame) < NSMinY(parent_frame)) { | 727 if (NSMinY(window_frame) < NSMinY(parent_frame)) { |
| 729 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; | 728 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; |
| 730 } | 729 } |
| 731 } | 730 } |
| 732 | 731 |
| 733 return corner_flags; | 732 return corner_flags; |
| 734 } | 733 } |
| OLD | NEW |