| 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/scoped_block.h" | 12 #include "base/mac/scoped_block.h" |
| 13 #include "base/mac/sdk_forward_declarations.h" | 13 #include "base/mac/sdk_forward_declarations.h" |
| 14 #include "base/message_loop/message_loop.h" | |
| 15 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 16 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #import "chrome/browser/ui/cocoa/bubble_view.h" | 18 #import "chrome/browser/ui/cocoa/bubble_view.h" |
| 19 #include "components/url_formatter/elide_url.h" | 19 #include "components/url_formatter/elide_url.h" |
| 20 #include "components/url_formatter/url_formatter.h" | 20 #include "components/url_formatter/url_formatter.h" |
| 21 #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
" |
| 22 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect
.h" | 22 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect
.h" |
| 23 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSColor+Luminance.h" | 23 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSColor+Luminance.h" |
| 24 #include "ui/base/cocoa/cocoa_base_utils.h" | 24 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 25 #include "ui/base/cocoa/window_size_constants.h" | 25 #include "ui/base/cocoa/window_size_constants.h" |
| 26 #include "ui/gfx/font_list.h" | 26 #include "ui/gfx/font_list.h" |
| 27 #include "ui/gfx/geometry/point.h" | 27 #include "ui/gfx/geometry/point.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 return; | 246 return; |
| 247 else | 247 else |
| 248 CancelExpandTimer(); | 248 CancelExpandTimer(); |
| 249 | 249 |
| 250 // If the bubble has been expanded, the user has already hovered over a link | 250 // If the bubble has been expanded, the user has already hovered over a link |
| 251 // to trigger the expanded state. Don't wait to change the bubble in this | 251 // to trigger the expanded state. Don't wait to change the bubble in this |
| 252 // case -- immediately expand or contract to fit the URL. | 252 // case -- immediately expand or contract to fit the URL. |
| 253 if (is_expanded_ && !url.is_empty()) { | 253 if (is_expanded_ && !url.is_empty()) { |
| 254 ExpandBubble(); | 254 ExpandBubble(); |
| 255 } else if (original_url_text.length() > status.length()) { | 255 } else if (original_url_text.length() > status.length()) { |
| 256 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 256 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 257 base::Bind(&StatusBubbleMac::ExpandBubble, | 257 FROM_HERE, base::Bind(&StatusBubbleMac::ExpandBubble, |
| 258 expand_timer_factory_.GetWeakPtr()), | 258 expand_timer_factory_.GetWeakPtr()), |
| 259 base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS)); | 259 base::TimeDelta::FromMilliseconds(kExpandHoverDelayMS)); |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 | 262 |
| 263 void StatusBubbleMac::SetText(const base::string16& text, bool is_url) { | 263 void StatusBubbleMac::SetText(const base::string16& text, bool is_url) { |
| 264 // The status bubble allows the status and URL strings to be set | 264 // The status bubble allows the status and URL strings to be set |
| 265 // independently. Whichever was set non-empty most recently will be the | 265 // independently. Whichever was set non-empty most recently will be the |
| 266 // value displayed. When both are empty, the status bubble hides. | 266 // value displayed. When both are empty, the status bubble hides. |
| 267 | 267 |
| 268 NSString* text_ns = base::SysUTF16ToNSString(text); | 268 NSString* text_ns = base::SysUTF16ToNSString(text); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 DCHECK(state_ == kBubbleShowingTimer || state_ == kBubbleHidingTimer); | 600 DCHECK(state_ == kBubbleShowingTimer || state_ == kBubbleHidingTimer); |
| 601 | 601 |
| 602 if (immediate_) { | 602 if (immediate_) { |
| 603 TimerFired(); | 603 TimerFired(); |
| 604 return; | 604 return; |
| 605 } | 605 } |
| 606 | 606 |
| 607 // There can only be one running timer. | 607 // There can only be one running timer. |
| 608 CancelTimer(); | 608 CancelTimer(); |
| 609 | 609 |
| 610 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 610 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 611 FROM_HERE, |
| 611 base::Bind(&StatusBubbleMac::TimerFired, timer_factory_.GetWeakPtr()), | 612 base::Bind(&StatusBubbleMac::TimerFired, timer_factory_.GetWeakPtr()), |
| 612 base::TimeDelta::FromMilliseconds(delay_ms)); | 613 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 613 } | 614 } |
| 614 | 615 |
| 615 void StatusBubbleMac::CancelTimer() { | 616 void StatusBubbleMac::CancelTimer() { |
| 616 DCHECK([NSThread isMainThread]); | 617 DCHECK([NSThread isMainThread]); |
| 617 | 618 |
| 618 if (timer_factory_.HasWeakPtrs()) | 619 if (timer_factory_.HasWeakPtrs()) |
| 619 timer_factory_.InvalidateWeakPtrs(); | 620 timer_factory_.InvalidateWeakPtrs(); |
| 620 } | 621 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 } | 847 } |
| 847 } | 848 } |
| 848 | 849 |
| 849 // Round the top corners when the bubble is below the parent window. | 850 // Round the top corners when the bubble is below the parent window. |
| 850 if (NSMinY(window_frame) < NSMinY(parent_frame)) { | 851 if (NSMinY(window_frame) < NSMinY(parent_frame)) { |
| 851 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; | 852 corner_flags |= kRoundedTopLeftCorner | kRoundedTopRightCorner; |
| 852 } | 853 } |
| 853 | 854 |
| 854 return corner_flags; | 855 return corner_flags; |
| 855 } | 856 } |
| OLD | NEW |