| 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" | |
| 13 #include "base/mac/scoped_block.h" | 12 #include "base/mac/scoped_block.h" |
| 14 #include "base/mac/sdk_forward_declarations.h" | 13 #include "base/mac/sdk_forward_declarations.h" |
| 15 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 16 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 19 #import "chrome/browser/ui/cocoa/bubble_view.h" | 18 #import "chrome/browser/ui/cocoa/bubble_view.h" |
| 20 #include "components/url_formatter/elide_url.h" | 19 #include "components/url_formatter/elide_url.h" |
| 21 #include "components/url_formatter/url_formatter.h" | 20 #include "components/url_formatter/url_formatter.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
" |
| (...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 NSMaxX(actual_window_frame) - NSWidth(window_frame); | 742 NSMaxX(actual_window_frame) - NSWidth(window_frame); |
| 744 } | 743 } |
| 745 actual_window_frame.size.width = NSWidth(window_frame); | 744 actual_window_frame.size.width = NSWidth(window_frame); |
| 746 | 745 |
| 747 // Do not expand if it's going to cover mouse location. | 746 // Do not expand if it's going to cover mouse location. |
| 748 gfx::Point p = GetMouseLocation(); | 747 gfx::Point p = GetMouseLocation(); |
| 749 if (NSPointInRect(NSMakePoint(p.x(), p.y()), actual_window_frame)) | 748 if (NSPointInRect(NSMakePoint(p.x(), p.y()), actual_window_frame)) |
| 750 return; | 749 return; |
| 751 | 750 |
| 752 // Get the current corner flags and see what needs to change based on the | 751 // Get the current corner flags and see what needs to change based on the |
| 753 // expansion. This is only needed on Lion, which has rounded window bottoms. | 752 // expansion. |
| 754 if (base::mac::IsOSLionOrLater()) { | 753 unsigned long corner_flags = [[window_ contentView] cornerFlags]; |
| 755 unsigned long corner_flags = [[window_ contentView] cornerFlags]; | 754 corner_flags |= OSDependentCornerFlags(actual_window_frame); |
| 756 corner_flags |= OSDependentCornerFlags(actual_window_frame); | 755 [[window_ contentView] setCornerFlags:corner_flags]; |
| 757 [[window_ contentView] setCornerFlags:corner_flags]; | 756 |
| 758 } | |
| 759 | 757 |
| 760 [NSAnimationContext beginGrouping]; | 758 [NSAnimationContext beginGrouping]; |
| 761 [[NSAnimationContext currentContext] setDuration:kExpansionDurationSeconds]; | 759 [[NSAnimationContext currentContext] setDuration:kExpansionDurationSeconds]; |
| 762 [[window_ animator] setFrame:actual_window_frame display:YES]; | 760 [[window_ animator] setFrame:actual_window_frame display:YES]; |
| 763 [NSAnimationContext endGrouping]; | 761 [NSAnimationContext endGrouping]; |
| 764 } | 762 } |
| 765 | 763 |
| 766 void StatusBubbleMac::UpdateSizeAndPosition() { | 764 void StatusBubbleMac::UpdateSizeAndPosition() { |
| 767 if (!window_) | 765 if (!window_) |
| 768 return; | 766 return; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 size.width = kWindowWidthPercent * screenRect.size.width; | 824 size.width = kWindowWidthPercent * screenRect.size.width; |
| 827 } | 825 } |
| 828 | 826 |
| 829 screenRect.size = size; | 827 screenRect.size = size; |
| 830 return screenRect; | 828 return screenRect; |
| 831 } | 829 } |
| 832 | 830 |
| 833 unsigned long StatusBubbleMac::OSDependentCornerFlags(NSRect window_frame) { | 831 unsigned long StatusBubbleMac::OSDependentCornerFlags(NSRect window_frame) { |
| 834 unsigned long corner_flags = 0; | 832 unsigned long corner_flags = 0; |
| 835 | 833 |
| 836 if (base::mac::IsOSLionOrLater()) { | 834 NSRect parent_frame = [parent_ frame]; |
| 837 NSRect parent_frame = [parent_ frame]; | |
| 838 | 835 |
| 839 // Round the bottom corners when they're right up against the | 836 // Round the bottom corners when they're right up against the |
| 840 // corresponding edge of the parent window, or when below the parent | 837 // corresponding edge of the parent window, or when below the parent |
| 841 // window. | 838 // window. |
| 842 if (NSMinY(window_frame) <= NSMinY(parent_frame)) { | 839 if (NSMinY(window_frame) <= NSMinY(parent_frame)) { |
| 843 if (NSMinX(window_frame) == NSMinX(parent_frame)) { | 840 if (NSMinX(window_frame) == NSMinX(parent_frame)) { |
| 844 corner_flags |= kRoundedBottomLeftCorner; | 841 corner_flags |= kRoundedBottomLeftCorner; |
| 845 } | |
| 846 | |
| 847 if (NSMaxX(window_frame) == NSMaxX(parent_frame)) { | |
| 848 corner_flags |= kRoundedBottomRightCorner; | |
| 849 } | |
| 850 } | 842 } |
| 851 | 843 |
| 852 // Round the top corners when the bubble is below the parent window. | 844 if (NSMaxX(window_frame) == NSMaxX(parent_frame)) { |
| 853 if (NSMinY(window_frame) < NSMinY(parent_frame)) { | 845 corner_flags |= kRoundedBottomRightCorner; |
| 854 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; | |
| 855 } | 846 } |
| 856 } | 847 } |
| 857 | 848 |
| 849 // Round the top corners when the bubble is below the parent window. |
| 850 if (NSMinY(window_frame) < NSMinY(parent_frame)) { |
| 851 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; |
| 852 } |
| 853 |
| 858 return corner_flags; | 854 return corner_flags; |
| 859 } | 855 } |
| OLD | NEW |