| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 completion_handler_factory_.InvalidateWeakPtrs(); | 195 completion_handler_factory_.InvalidateWeakPtrs(); |
| 196 Detach(); | 196 Detach(); |
| 197 [window_ release]; | 197 [window_ release]; |
| 198 window_ = nil; | 198 window_ = nil; |
| 199 } | 199 } |
| 200 | 200 |
| 201 void StatusBubbleMac::SetStatus(const base::string16& status) { | 201 void StatusBubbleMac::SetStatus(const base::string16& status) { |
| 202 SetText(status, false); | 202 SetText(status, false); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void StatusBubbleMac::SetURL(const GURL& url, const std::string& languages) { | 205 void StatusBubbleMac::SetURL(const GURL& url) { |
| 206 url_ = url; | 206 url_ = url; |
| 207 languages_ = languages; | |
| 208 | 207 |
| 209 CGFloat bubble_width = NSWidth([window_ frame]); | 208 CGFloat bubble_width = NSWidth([window_ frame]); |
| 210 if (state_ == kBubbleHidden) { | 209 if (state_ == kBubbleHidden) { |
| 211 // TODO(rohitrao): The window size is expected to be (1,1) whenever the | 210 // TODO(rohitrao): The window size is expected to be (1,1) whenever the |
| 212 // window is hidden, but the GPU bots are hitting cases where this is not | 211 // window is hidden, but the GPU bots are hitting cases where this is not |
| 213 // true. Instead of enforcing this invariant with a DCHECK, add temporary | 212 // true. Instead of enforcing this invariant with a DCHECK, add temporary |
| 214 // logging to try and debug it and fix up the window size if needed. | 213 // logging to try and debug it and fix up the window size if needed. |
| 215 // This logging is temporary and should be removed: crbug.com/467998 | 214 // This logging is temporary and should be removed: crbug.com/467998 |
| 216 NSRect frame = [window_ frame]; | 215 NSRect frame = [window_ frame]; |
| 217 if (!CGSizeEqualToSize(frame.size, ui::kWindowSizeDeterminedLater.size)) { | 216 if (!CGSizeEqualToSize(frame.size, ui::kWindowSizeDeterminedLater.size)) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 229 kTextPadding); | 228 kTextPadding); |
| 230 | 229 |
| 231 // Scale from view to window coordinates before eliding URL string. | 230 // Scale from view to window coordinates before eliding URL string. |
| 232 NSSize scaled_width = NSMakeSize(text_width, 0); | 231 NSSize scaled_width = NSMakeSize(text_width, 0); |
| 233 scaled_width = [[parent_ contentView] convertSize:scaled_width fromView:nil]; | 232 scaled_width = [[parent_ contentView] convertSize:scaled_width fromView:nil]; |
| 234 text_width = static_cast<int>(scaled_width.width); | 233 text_width = static_cast<int>(scaled_width.width); |
| 235 NSFont* font = [[window_ contentView] font]; | 234 NSFont* font = [[window_ contentView] font]; |
| 236 gfx::FontList font_list_chr( | 235 gfx::FontList font_list_chr( |
| 237 gfx::Font(gfx::PlatformFont::CreateFromNativeFont(font))); | 236 gfx::Font(gfx::PlatformFont::CreateFromNativeFont(font))); |
| 238 | 237 |
| 239 base::string16 original_url_text = url_formatter::FormatUrl(url, languages); | 238 base::string16 original_url_text = url_formatter::FormatUrl(url); |
| 240 base::string16 status = | 239 base::string16 status = |
| 241 url_formatter::ElideUrl(url, font_list_chr, text_width, languages); | 240 url_formatter::ElideUrl(url, font_list_chr, text_width); |
| 242 | 241 |
| 243 SetText(status, true); | 242 SetText(status, true); |
| 244 | 243 |
| 245 // In testing, don't use animation. When ExpandBubble is tested, it is | 244 // In testing, don't use animation. When ExpandBubble is tested, it is |
| 246 // called explicitly. | 245 // called explicitly. |
| 247 if (immediate_) | 246 if (immediate_) |
| 248 return; | 247 return; |
| 249 else | 248 else |
| 250 CancelExpandTimer(); | 249 CancelExpandTimer(); |
| 251 | 250 |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 NSRect window_frame = CalculateWindowFrame(/*expand=*/true); | 701 NSRect window_frame = CalculateWindowFrame(/*expand=*/true); |
| 703 CGFloat max_bubble_width = NSWidth(window_frame); | 702 CGFloat max_bubble_width = NSWidth(window_frame); |
| 704 CGFloat standard_bubble_width = | 703 CGFloat standard_bubble_width = |
| 705 NSWidth(CalculateWindowFrame(/*expand=*/false)); | 704 NSWidth(CalculateWindowFrame(/*expand=*/false)); |
| 706 | 705 |
| 707 // Generate the URL string that fits in the expanded bubble. | 706 // Generate the URL string that fits in the expanded bubble. |
| 708 NSFont* font = [[window_ contentView] font]; | 707 NSFont* font = [[window_ contentView] font]; |
| 709 gfx::FontList font_list_chr( | 708 gfx::FontList font_list_chr( |
| 710 gfx::Font(gfx::PlatformFont::CreateFromNativeFont(font))); | 709 gfx::Font(gfx::PlatformFont::CreateFromNativeFont(font))); |
| 711 base::string16 expanded_url = url_formatter::ElideUrl( | 710 base::string16 expanded_url = url_formatter::ElideUrl( |
| 712 url_, font_list_chr, max_bubble_width, languages_); | 711 url_, font_list_chr, max_bubble_width); |
| 713 | 712 |
| 714 // Scale width from gfx::Font in view coordinates to window coordinates. | 713 // Scale width from gfx::Font in view coordinates to window coordinates. |
| 715 int required_width_for_string = | 714 int required_width_for_string = |
| 716 gfx::GetStringWidth(expanded_url, font_list_chr) + | 715 gfx::GetStringWidth(expanded_url, font_list_chr) + |
| 717 kTextPadding * 2 + kBubbleViewTextPositionX; | 716 kTextPadding * 2 + kBubbleViewTextPositionX; |
| 718 NSSize scaled_width = NSMakeSize(required_width_for_string, 0); | 717 NSSize scaled_width = NSMakeSize(required_width_for_string, 0); |
| 719 scaled_width = [[parent_ contentView] convertSize:scaled_width toView:nil]; | 718 scaled_width = [[parent_ contentView] convertSize:scaled_width toView:nil]; |
| 720 required_width_for_string = scaled_width.width; | 719 required_width_for_string = scaled_width.width; |
| 721 | 720 |
| 722 // The expanded width must be at least as wide as the standard width, but no | 721 // The expanded width must be at least as wide as the standard width, but no |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 } | 850 } |
| 852 | 851 |
| 853 // Round the top corners when the bubble is below the parent window. | 852 // Round the top corners when the bubble is below the parent window. |
| 854 if (NSMinY(window_frame) < NSMinY(parent_frame)) { | 853 if (NSMinY(window_frame) < NSMinY(parent_frame)) { |
| 855 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; | 854 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; |
| 856 } | 855 } |
| 857 } | 856 } |
| 858 | 857 |
| 859 return corner_flags; | 858 return corner_flags; |
| 860 } | 859 } |
| OLD | NEW |