| 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" |
| 11 #include "base/debug/stack_trace.h" | 11 #include "base/debug/stack_trace.h" |
| 12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
| 13 #include "base/mac/scoped_block.h" | 13 #include "base/mac/scoped_block.h" |
| 14 #include "base/mac/sdk_forward_declarations.h" | 14 #include "base/mac/sdk_forward_declarations.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #import "chrome/browser/ui/cocoa/bubble_view.h" | 19 #import "chrome/browser/ui/cocoa/bubble_view.h" |
| 20 #include "chrome/browser/ui/elide_url.h" | |
| 21 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| 22 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" | 21 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" |
| 23 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect
.h" | 22 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect
.h" |
| 24 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSColor+Luminance.h" | 23 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSColor+Luminance.h" |
| 25 #include "ui/base/cocoa/window_size_constants.h" | 24 #include "ui/base/cocoa/window_size_constants.h" |
| 26 #include "ui/gfx/font_list.h" | 25 #include "ui/gfx/font_list.h" |
| 27 #include "ui/gfx/geometry/point.h" | 26 #include "ui/gfx/geometry/point.h" |
| 28 #include "ui/gfx/text_elider.h" | 27 #include "ui/gfx/text_elider.h" |
| 29 #include "ui/gfx/text_utils.h" | 28 #include "ui/gfx/text_utils.h" |
| 29 #include "ui/secure_display/elide_url.h" |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 const int kWindowHeight = 18; | 33 const int kWindowHeight = 18; |
| 34 | 34 |
| 35 // The width of the bubble in relation to the width of the parent window. | 35 // The width of the bubble in relation to the width of the parent window. |
| 36 const CGFloat kWindowWidthPercent = 1.0 / 3.0; | 36 const CGFloat kWindowWidthPercent = 1.0 / 3.0; |
| 37 | 37 |
| 38 // How close the mouse can get to the infobubble before it starts sliding | 38 // How close the mouse can get to the infobubble before it starts sliding |
| 39 // off-screen. | 39 // off-screen. |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // Scale from view to window coordinates before eliding URL string. | 229 // Scale from view to window coordinates before eliding URL string. |
| 230 NSSize scaled_width = NSMakeSize(text_width, 0); | 230 NSSize scaled_width = NSMakeSize(text_width, 0); |
| 231 scaled_width = [[parent_ contentView] convertSize:scaled_width fromView:nil]; | 231 scaled_width = [[parent_ contentView] convertSize:scaled_width fromView:nil]; |
| 232 text_width = static_cast<int>(scaled_width.width); | 232 text_width = static_cast<int>(scaled_width.width); |
| 233 NSFont* font = [[window_ contentView] font]; | 233 NSFont* font = [[window_ contentView] font]; |
| 234 gfx::FontList font_list_chr( | 234 gfx::FontList font_list_chr( |
| 235 gfx::Font(base::SysNSStringToUTF8([font fontName]), [font pointSize])); | 235 gfx::Font(base::SysNSStringToUTF8([font fontName]), [font pointSize])); |
| 236 | 236 |
| 237 base::string16 original_url_text = net::FormatUrl(url, languages); | 237 base::string16 original_url_text = net::FormatUrl(url, languages); |
| 238 base::string16 status = | 238 base::string16 status = |
| 239 ElideUrl(url, font_list_chr, text_width, languages); | 239 secure_display::ElideUrl(url, font_list_chr, text_width, languages); |
| 240 | 240 |
| 241 SetText(status, true); | 241 SetText(status, true); |
| 242 | 242 |
| 243 // In testing, don't use animation. When ExpandBubble is tested, it is | 243 // In testing, don't use animation. When ExpandBubble is tested, it is |
| 244 // called explicitly. | 244 // called explicitly. |
| 245 if (immediate_) | 245 if (immediate_) |
| 246 return; | 246 return; |
| 247 else | 247 else |
| 248 CancelExpandTimer(); | 248 CancelExpandTimer(); |
| 249 | 249 |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 // Calculate the width available for expanded and standard bubbles. | 698 // Calculate the width available for expanded and standard bubbles. |
| 699 NSRect window_frame = CalculateWindowFrame(/*expand=*/true); | 699 NSRect window_frame = CalculateWindowFrame(/*expand=*/true); |
| 700 CGFloat max_bubble_width = NSWidth(window_frame); | 700 CGFloat max_bubble_width = NSWidth(window_frame); |
| 701 CGFloat standard_bubble_width = | 701 CGFloat standard_bubble_width = |
| 702 NSWidth(CalculateWindowFrame(/*expand=*/false)); | 702 NSWidth(CalculateWindowFrame(/*expand=*/false)); |
| 703 | 703 |
| 704 // Generate the URL string that fits in the expanded bubble. | 704 // Generate the URL string that fits in the expanded bubble. |
| 705 NSFont* font = [[window_ contentView] font]; | 705 NSFont* font = [[window_ contentView] font]; |
| 706 gfx::FontList font_list_chr( | 706 gfx::FontList font_list_chr( |
| 707 gfx::Font(base::SysNSStringToUTF8([font fontName]), [font pointSize])); | 707 gfx::Font(base::SysNSStringToUTF8([font fontName]), [font pointSize])); |
| 708 base::string16 expanded_url = ElideUrl( | 708 base::string16 expanded_url = secure_display::ElideUrl( |
| 709 url_, font_list_chr, max_bubble_width, languages_); | 709 url_, font_list_chr, max_bubble_width, languages_); |
| 710 | 710 |
| 711 // Scale width from gfx::Font in view coordinates to window coordinates. | 711 // Scale width from gfx::Font in view coordinates to window coordinates. |
| 712 int required_width_for_string = | 712 int required_width_for_string = |
| 713 gfx::GetStringWidth(expanded_url, font_list_chr) + | 713 gfx::GetStringWidth(expanded_url, font_list_chr) + |
| 714 kTextPadding * 2 + kBubbleViewTextPositionX; | 714 kTextPadding * 2 + kBubbleViewTextPositionX; |
| 715 NSSize scaled_width = NSMakeSize(required_width_for_string, 0); | 715 NSSize scaled_width = NSMakeSize(required_width_for_string, 0); |
| 716 scaled_width = [[parent_ contentView] convertSize:scaled_width toView:nil]; | 716 scaled_width = [[parent_ contentView] convertSize:scaled_width toView:nil]; |
| 717 required_width_for_string = scaled_width.width; | 717 required_width_for_string = scaled_width.width; |
| 718 | 718 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 } | 848 } |
| 849 | 849 |
| 850 // Round the top corners when the bubble is below the parent window. | 850 // Round the top corners when the bubble is below the parent window. |
| 851 if (NSMinY(window_frame) < NSMinY(parent_frame)) { | 851 if (NSMinY(window_frame) < NSMinY(parent_frame)) { |
| 852 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; | 852 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; |
| 853 } | 853 } |
| 854 } | 854 } |
| 855 | 855 |
| 856 return corner_flags; | 856 return corner_flags; |
| 857 } | 857 } |
| OLD | NEW |