| 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 "components/url_formatter/elide_url.h" | 20 #include "components/url_formatter/elide_url.h" |
| 21 #include "components/url_formatter/url_formatter.h" | 21 #include "components/url_formatter/url_formatter.h" |
| 22 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h
" | 22 #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" | 23 #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" | 24 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSColor+Luminance.h" |
| 25 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 25 #include "ui/base/cocoa/window_size_constants.h" | 26 #include "ui/base/cocoa/window_size_constants.h" |
| 26 #include "ui/gfx/font_list.h" | 27 #include "ui/gfx/font_list.h" |
| 27 #include "ui/gfx/geometry/point.h" | 28 #include "ui/gfx/geometry/point.h" |
| 28 #include "ui/gfx/platform_font.h" | 29 #include "ui/gfx/platform_font.h" |
| 29 #include "ui/gfx/text_elider.h" | 30 #include "ui/gfx/text_elider.h" |
| 30 #include "ui/gfx/text_utils.h" | 31 #include "ui/gfx/text_utils.h" |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 const int kWindowHeight = 18; | 35 const int kWindowHeight = 18; |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 NSRect base_rect; | 357 NSRect base_rect; |
| 357 if ([delegate_ respondsToSelector:@selector(statusBubbleBaseFrame)]) { | 358 if ([delegate_ respondsToSelector:@selector(statusBubbleBaseFrame)]) { |
| 358 base_rect = [delegate_ statusBubbleBaseFrame]; | 359 base_rect = [delegate_ statusBubbleBaseFrame]; |
| 359 } else { | 360 } else { |
| 360 base_rect = [[parent_ contentView] bounds]; | 361 base_rect = [[parent_ contentView] bounds]; |
| 361 base_rect = [[parent_ contentView] convertRect:base_rect toView:nil]; | 362 base_rect = [[parent_ contentView] convertRect:base_rect toView:nil]; |
| 362 } | 363 } |
| 363 | 364 |
| 364 // To start, assume default positioning in the lower left corner. | 365 // To start, assume default positioning in the lower left corner. |
| 365 // The window_frame position is in global (screen) coordinates. | 366 // The window_frame position is in global (screen) coordinates. |
| 366 window_frame.origin = [parent_ convertBaseToScreen:base_rect.origin]; | 367 window_frame.origin = |
| 368 ui::ConvertPointFromWindowToScreen(parent_, base_rect.origin); |
| 367 | 369 |
| 368 // Get the cursor position relative to the top right corner of the bubble. | 370 // Get the cursor position relative to the top right corner of the bubble. |
| 369 gfx::Point relative_pos(mouse_pos.x() - NSMaxX(window_frame), | 371 gfx::Point relative_pos(mouse_pos.x() - NSMaxX(window_frame), |
| 370 mouse_pos.y() - NSMaxY(window_frame)); | 372 mouse_pos.y() - NSMaxY(window_frame)); |
| 371 | 373 |
| 372 // If the mouse is in a position where we think it would move the | 374 // If the mouse is in a position where we think it would move the |
| 373 // status bubble, figure out where and how the bubble should be moved, and | 375 // status bubble, figure out where and how the bubble should be moved, and |
| 374 // what sorts of corners it should have. | 376 // what sorts of corners it should have. |
| 375 unsigned long corner_flags; | 377 unsigned long corner_flags; |
| 376 if (relative_pos.y() < kMousePadding && | 378 if (relative_pos.y() < kMousePadding && |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 Attach(); | 806 Attach(); |
| 805 UpdateSizeAndPosition(); | 807 UpdateSizeAndPosition(); |
| 806 } | 808 } |
| 807 | 809 |
| 808 NSRect StatusBubbleMac::CalculateWindowFrame(bool expanded_width) { | 810 NSRect StatusBubbleMac::CalculateWindowFrame(bool expanded_width) { |
| 809 DCHECK(parent_); | 811 DCHECK(parent_); |
| 810 | 812 |
| 811 NSRect screenRect; | 813 NSRect screenRect; |
| 812 if ([delegate_ respondsToSelector:@selector(statusBubbleBaseFrame)]) { | 814 if ([delegate_ respondsToSelector:@selector(statusBubbleBaseFrame)]) { |
| 813 screenRect = [delegate_ statusBubbleBaseFrame]; | 815 screenRect = [delegate_ statusBubbleBaseFrame]; |
| 814 screenRect.origin = [parent_ convertBaseToScreen:screenRect.origin]; | 816 screenRect = [parent_ convertRectToScreen:screenRect]; |
| 815 } else { | 817 } else { |
| 816 screenRect = [parent_ frame]; | 818 screenRect = [parent_ frame]; |
| 817 } | 819 } |
| 818 | 820 |
| 819 NSSize size = NSMakeSize(0, kWindowHeight); | 821 NSSize size = NSMakeSize(0, kWindowHeight); |
| 820 size = [[parent_ contentView] convertSize:size toView:nil]; | 822 size = [[parent_ contentView] convertSize:size toView:nil]; |
| 821 | 823 |
| 822 if (expanded_width) { | 824 if (expanded_width) { |
| 823 size.width = screenRect.size.width; | 825 size.width = screenRect.size.width; |
| 824 } else { | 826 } else { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 849 } | 851 } |
| 850 | 852 |
| 851 // Round the top corners when the bubble is below the parent window. | 853 // Round the top corners when the bubble is below the parent window. |
| 852 if (NSMinY(window_frame) < NSMinY(parent_frame)) { | 854 if (NSMinY(window_frame) < NSMinY(parent_frame)) { |
| 853 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; | 855 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; |
| 854 } | 856 } |
| 855 } | 857 } |
| 856 | 858 |
| 857 return corner_flags; | 859 return corner_flags; |
| 858 } | 860 } |
| OLD | NEW |