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/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
12 #include "base/mac/scoped_block.h" | 13 #include "base/mac/scoped_block.h" |
13 #include "base/mac/sdk_forward_declarations.h" | 14 #include "base/mac/sdk_forward_declarations.h" |
14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #import "chrome/browser/ui/cocoa/bubble_view.h" | 19 #import "chrome/browser/ui/cocoa/bubble_view.h" |
19 #include "chrome/browser/ui/elide_url.h" | 20 #include "chrome/browser/ui/elide_url.h" |
20 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 void StatusBubbleMac::SetStatus(const base::string16& status) { | 199 void StatusBubbleMac::SetStatus(const base::string16& status) { |
199 SetText(status, false); | 200 SetText(status, false); |
200 } | 201 } |
201 | 202 |
202 void StatusBubbleMac::SetURL(const GURL& url, const std::string& languages) { | 203 void StatusBubbleMac::SetURL(const GURL& url, const std::string& languages) { |
203 url_ = url; | 204 url_ = url; |
204 languages_ = languages; | 205 languages_ = languages; |
205 | 206 |
206 CGFloat bubble_width = NSWidth([window_ frame]); | 207 CGFloat bubble_width = NSWidth([window_ frame]); |
207 if (state_ == kBubbleHidden) { | 208 if (state_ == kBubbleHidden) { |
208 DCHECK_EQ(ui::kWindowSizeDeterminedLater.size.width, | 209 // TODO(rohitrao): The window size is expected to be (1,1) whenever the |
209 [window_ frame].size.width); | 210 // window is hidden, but the GPU bots are hitting cases where this is not |
210 DCHECK_EQ(ui::kWindowSizeDeterminedLater.size.height, | 211 // true. Instead of enforcing this invariant with a DCHECK, add temporary |
211 [window_ frame].size.height); | 212 // logging to try and debug it and fix up the window size if needed. |
213 // This logging is temporary and should be removed: crbug.com/467998 | |
214 NSRect frame = [window_ frame]; | |
215 if (!CGSizeEqualToSize(frame.size, ui::kWindowSizeDeterminedLater.size)) { | |
216 LOG(ERROR) << "Window size should be (1,1), but is instead (" | |
217 << frame.size.width << "," << frame.size.height << ")"; | |
218 LOG(ERROR) << base::debug::StackTrace().ToString(); | |
219 frame.size = ui::kWindowSizeDeterminedLater.size; | |
Ken Russell (switch to Gerrit)
2015/03/17 22:36:23
Note: I'm not sure how well base::debug::StackTrac
| |
220 [window_ setFrame:frame display:NO]; | |
221 } | |
212 bubble_width = NSWidth(CalculateWindowFrame(/*expand=*/false)); | 222 bubble_width = NSWidth(CalculateWindowFrame(/*expand=*/false)); |
213 } | 223 } |
214 | 224 |
215 int text_width = static_cast<int>(bubble_width - | 225 int text_width = static_cast<int>(bubble_width - |
216 kBubbleViewTextPositionX - | 226 kBubbleViewTextPositionX - |
217 kTextPadding); | 227 kTextPadding); |
218 | 228 |
219 // Scale from view to window coordinates before eliding URL string. | 229 // Scale from view to window coordinates before eliding URL string. |
220 NSSize scaled_width = NSMakeSize(text_width, 0); | 230 NSSize scaled_width = NSMakeSize(text_width, 0); |
221 scaled_width = [[parent_ contentView] convertSize:scaled_width fromView:nil]; | 231 scaled_width = [[parent_ contentView] convertSize:scaled_width fromView:nil]; |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
752 } | 762 } |
753 | 763 |
754 void StatusBubbleMac::UpdateSizeAndPosition() { | 764 void StatusBubbleMac::UpdateSizeAndPosition() { |
755 if (!window_) | 765 if (!window_) |
756 return; | 766 return; |
757 | 767 |
758 // There is no need to update the size if the bubble is hidden. | 768 // There is no need to update the size if the bubble is hidden. |
759 if (state_ == kBubbleHidden) { | 769 if (state_ == kBubbleHidden) { |
760 // Verify that hidden bubbles always have size equal to | 770 // Verify that hidden bubbles always have size equal to |
761 // ui::kWindowSizeDeterminedLater. | 771 // ui::kWindowSizeDeterminedLater. |
762 DCHECK_EQ(ui::kWindowSizeDeterminedLater.size.width, | 772 |
763 [window_ frame].size.width); | 773 // TODO(rohitrao): The GPU bots are hitting cases where this is not true. |
764 DCHECK_EQ(ui::kWindowSizeDeterminedLater.size.height, | 774 // Instead of enforcing this invariant with a DCHECK, add temporary logging |
765 [window_ frame].size.height); | 775 // to try and debug it and fix up the window size if needed. |
776 // This logging is temporary and should be removed: crbug.com/467998 | |
777 NSRect frame = [window_ frame]; | |
778 if (!CGSizeEqualToSize(frame.size, ui::kWindowSizeDeterminedLater.size)) { | |
779 LOG(ERROR) << "Window size should be (1,1), but is instead (" | |
780 << frame.size.width << "," << frame.size.height << ")"; | |
781 LOG(ERROR) << base::debug::StackTrace().ToString(); | |
782 frame.size = ui::kWindowSizeDeterminedLater.size; | |
783 [window_ setFrame:frame display:YES]; | |
784 } | |
766 return; | 785 return; |
767 } | 786 } |
768 | 787 |
769 SetFrameAvoidingMouse(CalculateWindowFrame(/*expand=*/false), | 788 SetFrameAvoidingMouse(CalculateWindowFrame(/*expand=*/false), |
770 GetMouseLocation()); | 789 GetMouseLocation()); |
771 } | 790 } |
772 | 791 |
773 void StatusBubbleMac::SwitchParentWindow(NSWindow* parent) { | 792 void StatusBubbleMac::SwitchParentWindow(NSWindow* parent) { |
774 DCHECK(parent); | 793 DCHECK(parent); |
775 DCHECK(is_attached()); | 794 DCHECK(is_attached()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
824 } | 843 } |
825 | 844 |
826 // Round the top corners when the bubble is below the parent window. | 845 // Round the top corners when the bubble is below the parent window. |
827 if (NSMinY(window_frame) < NSMinY(parent_frame)) { | 846 if (NSMinY(window_frame) < NSMinY(parent_frame)) { |
828 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; | 847 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; |
829 } | 848 } |
830 } | 849 } |
831 | 850 |
832 return corner_flags; | 851 return corner_flags; |
833 } | 852 } |
OLD | NEW |