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