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/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #import "chrome/browser/ui/cocoa/bubble_view.h" | 16 #import "chrome/browser/ui/cocoa/bubble_view.h" |
17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
18 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 18 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
19 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" | 19 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" |
20 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" | 20 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" |
21 #include "ui/base/cocoa/window_size_constants.h" | 21 #include "ui/base/cocoa/window_size_constants.h" |
22 #include "ui/base/text/text_elider.h" | 22 #include "ui/gfx/text_elider.h" |
23 #include "ui/gfx/font.h" | 23 #include "ui/gfx/font.h" |
24 #include "ui/gfx/point.h" | 24 #include "ui/gfx/point.h" |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 const int kWindowHeight = 18; | 28 const int kWindowHeight = 18; |
29 | 29 |
30 // The width of the bubble in relation to the width of the parent window. | 30 // The width of the bubble in relation to the width of the parent window. |
31 const CGFloat kWindowWidthPercent = 1.0 / 3.0; | 31 const CGFloat kWindowWidthPercent = 1.0 / 3.0; |
32 | 32 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 147 |
148 // Scale from view to window coordinates before eliding URL string. | 148 // Scale from view to window coordinates before eliding URL string. |
149 NSSize scaled_width = NSMakeSize(text_width, 0); | 149 NSSize scaled_width = NSMakeSize(text_width, 0); |
150 scaled_width = [[parent_ contentView] convertSize:scaled_width fromView:nil]; | 150 scaled_width = [[parent_ contentView] convertSize:scaled_width fromView:nil]; |
151 text_width = static_cast<int>(scaled_width.width); | 151 text_width = static_cast<int>(scaled_width.width); |
152 NSFont* font = [[window_ contentView] font]; | 152 NSFont* font = [[window_ contentView] font]; |
153 gfx::Font font_chr(base::SysNSStringToUTF8([font fontName]), | 153 gfx::Font font_chr(base::SysNSStringToUTF8([font fontName]), |
154 [font pointSize]); | 154 [font pointSize]); |
155 | 155 |
156 string16 original_url_text = net::FormatUrl(url, languages); | 156 string16 original_url_text = net::FormatUrl(url, languages); |
157 string16 status = ui::ElideUrl(url, font_chr, text_width, languages); | 157 string16 status = gfx::ElideUrl(url, font_chr, text_width, languages); |
158 | 158 |
159 SetText(status, true); | 159 SetText(status, true); |
160 | 160 |
161 // In testing, don't use animation. When ExpandBubble is tested, it is | 161 // In testing, don't use animation. When ExpandBubble is tested, it is |
162 // called explicitly. | 162 // called explicitly. |
163 if (immediate_) | 163 if (immediate_) |
164 return; | 164 return; |
165 else | 165 else |
166 CancelExpandTimer(); | 166 CancelExpandTimer(); |
167 | 167 |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 // Calculate the width available for expanded and standard bubbles. | 616 // Calculate the width available for expanded and standard bubbles. |
617 NSRect window_frame = CalculateWindowFrame(/*expand=*/true); | 617 NSRect window_frame = CalculateWindowFrame(/*expand=*/true); |
618 CGFloat max_bubble_width = NSWidth(window_frame); | 618 CGFloat max_bubble_width = NSWidth(window_frame); |
619 CGFloat standard_bubble_width = | 619 CGFloat standard_bubble_width = |
620 NSWidth(CalculateWindowFrame(/*expand=*/false)); | 620 NSWidth(CalculateWindowFrame(/*expand=*/false)); |
621 | 621 |
622 // Generate the URL string that fits in the expanded bubble. | 622 // Generate the URL string that fits in the expanded bubble. |
623 NSFont* font = [[window_ contentView] font]; | 623 NSFont* font = [[window_ contentView] font]; |
624 gfx::Font font_chr(base::SysNSStringToUTF8([font fontName]), | 624 gfx::Font font_chr(base::SysNSStringToUTF8([font fontName]), |
625 [font pointSize]); | 625 [font pointSize]); |
626 string16 expanded_url = ui::ElideUrl( | 626 string16 expanded_url = gfx::ElideUrl( |
627 url_, font_chr, max_bubble_width, languages_); | 627 url_, font_chr, max_bubble_width, languages_); |
628 | 628 |
629 // Scale width from gfx::Font in view coordinates to window coordinates. | 629 // Scale width from gfx::Font in view coordinates to window coordinates. |
630 int required_width_for_string = | 630 int required_width_for_string = |
631 font_chr.GetStringWidth(expanded_url) + | 631 font_chr.GetStringWidth(expanded_url) + |
632 kTextPadding * 2 + kBubbleViewTextPositionX; | 632 kTextPadding * 2 + kBubbleViewTextPositionX; |
633 NSSize scaled_width = NSMakeSize(required_width_for_string, 0); | 633 NSSize scaled_width = NSMakeSize(required_width_for_string, 0); |
634 scaled_width = [[parent_ contentView] convertSize:scaled_width toView:nil]; | 634 scaled_width = [[parent_ contentView] convertSize:scaled_width toView:nil]; |
635 required_width_for_string = scaled_width.width; | 635 required_width_for_string = scaled_width.width; |
636 | 636 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 } | 741 } |
742 | 742 |
743 // Round the top corners when the bubble is below the parent window. | 743 // Round the top corners when the bubble is below the parent window. |
744 if (NSMinY(window_frame) < NSMinY(parent_frame)) { | 744 if (NSMinY(window_frame) < NSMinY(parent_frame)) { |
745 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; | 745 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; |
746 } | 746 } |
747 } | 747 } |
748 | 748 |
749 return corner_flags; | 749 return corner_flags; |
750 } | 750 } |
OLD | NEW |