| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UI_COCOA_STATUS_BUBBLE_MAC_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_STATUS_BUBBLE_MAC_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_STATUS_BUBBLE_MAC_H_ | 6 #define CHROME_BROWSER_UI_COCOA_STATUS_BUBBLE_MAC_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #import <Cocoa/Cocoa.h> | 10 #import <Cocoa/Cocoa.h> |
| 11 #import <QuartzCore/QuartzCore.h> | 11 #import <QuartzCore/QuartzCore.h> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "chrome/browser/ui/status_bubble.h" | 16 #include "chrome/browser/ui/status_bubble.h" |
| 17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 | 18 |
| 19 class StatusBubbleMacTest; | 19 class StatusBubbleMacTest; |
| 20 @class StatusBubbleWindow; |
| 20 | 21 |
| 21 class StatusBubbleMac : public StatusBubble { | 22 class StatusBubbleMac : public StatusBubble { |
| 22 public: | 23 public: |
| 23 // The various states that a status bubble may be in. Public for delegate | 24 // The various states that a status bubble may be in. Public for delegate |
| 24 // access (for testing). | 25 // access (for testing). |
| 25 enum StatusBubbleState { | 26 enum StatusBubbleState { |
| 26 kBubbleHidden, // Fully hidden | 27 kBubbleHidden, // Fully hidden |
| 27 kBubbleShowingTimer, // Waiting to fade in | 28 kBubbleShowingTimer, // Waiting to fade in |
| 28 kBubbleShowingFadeIn, // In a fade-in transition | 29 kBubbleShowingFadeIn, // In a fade-in transition |
| 29 kBubbleShown, // Fully visible | 30 kBubbleShown, // Fully visible |
| (...skipping 14 matching lines...) Expand all Loading... |
| 44 | 45 |
| 45 // Mac-specific method: Update the size and position of the status bubble to | 46 // Mac-specific method: Update the size and position of the status bubble to |
| 46 // match the parent window. Safe to call even when the status bubble does not | 47 // match the parent window. Safe to call even when the status bubble does not |
| 47 // exist. | 48 // exist. |
| 48 void UpdateSizeAndPosition(); | 49 void UpdateSizeAndPosition(); |
| 49 | 50 |
| 50 // Mac-specific method: Change the parent window of the status bubble. Safe to | 51 // Mac-specific method: Change the parent window of the status bubble. Safe to |
| 51 // call even when the status bubble does not exist. | 52 // call even when the status bubble does not exist. |
| 52 void SwitchParentWindow(NSWindow* parent); | 53 void SwitchParentWindow(NSWindow* parent); |
| 53 | 54 |
| 54 // Delegate method called when a fade-in or fade-out transition has | |
| 55 // completed. This is public so that it may be visible to the CAAnimation | |
| 56 // delegate, which is an Objective-C object. | |
| 57 void AnimationDidStop(CAAnimation* animation, bool finished); | |
| 58 | |
| 59 // Expand the bubble to fit a URL too long for the standard bubble size. | 55 // Expand the bubble to fit a URL too long for the standard bubble size. |
| 60 void ExpandBubble(); | 56 void ExpandBubble(); |
| 61 | 57 |
| 62 protected: | 58 protected: |
| 63 // Get the current location of the mouse. Protected so that it can be | 59 // Get the current location of the mouse. Protected so that it can be |
| 64 // stubbed out for testing. | 60 // stubbed out for testing. |
| 65 virtual gfx::Point GetMouseLocation(); | 61 virtual gfx::Point GetMouseLocation(); |
| 66 | 62 |
| 67 private: | 63 private: |
| 68 friend class StatusBubbleMacTest; | 64 friend class StatusBubbleMacTest; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 90 bool is_attached() { return [window_ parentWindow] != nil; } | 86 bool is_attached() { return [window_ parentWindow] != nil; } |
| 91 | 87 |
| 92 // Begins fading the status bubble window in or out depending on the value | 88 // Begins fading the status bubble window in or out depending on the value |
| 93 // of |show|. This must be called from the appropriate fade state, | 89 // of |show|. This must be called from the appropriate fade state, |
| 94 // kBubbleShowingFadeIn or kBubbleHidingFadeOut, or from the appropriate | 90 // kBubbleShowingFadeIn or kBubbleHidingFadeOut, or from the appropriate |
| 95 // fully-shown/hidden state, kBubbleShown or kBubbleHidden. This may be | 91 // fully-shown/hidden state, kBubbleShown or kBubbleHidden. This may be |
| 96 // called at any point during a fade-in or fade-out; it is even possible to | 92 // called at any point during a fade-in or fade-out; it is even possible to |
| 97 // reverse a transition before it has completed. | 93 // reverse a transition before it has completed. |
| 98 void Fade(bool show); | 94 void Fade(bool show); |
| 99 | 95 |
| 96 // Starts an animation of the bubble window to a specific alpha value over a |
| 97 // specific period of time. |
| 98 void AnimateWindowAlpha(CGFloat alpha, NSTimeInterval duration); |
| 99 |
| 100 // Method called from the completion callbacks when a fade-in or fade-out |
| 101 // transition has completed. |
| 102 void AnimationDidStop(); |
| 103 |
| 100 // One-shot timer operations to manage the delays associated with the | 104 // One-shot timer operations to manage the delays associated with the |
| 101 // kBubbleShowingTimer and kBubbleHidingTimer states. StartTimer and | 105 // kBubbleShowingTimer and kBubbleHidingTimer states. StartTimer and |
| 102 // TimerFired must be called from one of these states. StartTimer may be | 106 // TimerFired must be called from one of these states. StartTimer may be |
| 103 // called while the timer is still running; in that case, the timer will be | 107 // called while the timer is still running; in that case, the timer will be |
| 104 // reset. CancelTimer may be called from any state. | 108 // reset. CancelTimer may be called from any state. |
| 105 void StartTimer(int64 time_ms); | 109 void StartTimer(int64 time_ms); |
| 106 void CancelTimer(); | 110 void CancelTimer(); |
| 107 void TimerFired(); | 111 void TimerFired(); |
| 108 | 112 |
| 109 // Begin the process of showing or hiding the status bubble. These may be | 113 // Begin the process of showing or hiding the status bubble. These may be |
| 110 // called from any state, and will take the appropriate action to initiate | 114 // called from any state, and will take the appropriate action to initiate |
| 111 // any state changes that may be needed. | 115 // any state changes that may be needed. |
| 112 void StartShowing(); | 116 void StartShowing(); |
| 113 void StartHiding(); | 117 void StartHiding(); |
| 114 | 118 |
| 115 // Cancel the expansion timer. | 119 // Cancel the expansion timer. |
| 116 void CancelExpandTimer(); | 120 void CancelExpandTimer(); |
| 117 | 121 |
| 118 // Sets the frame of the status bubble window to |window_frame|, adjusting | 122 // Sets the frame of the status bubble window to |window_frame|, adjusting |
| 119 // for the given mouse position if necessary. Protected for use in tests. | 123 // for the given mouse position if necessary. Protected for use in tests. |
| 120 void SetFrameAvoidingMouse(NSRect window_frame, const gfx::Point& mouse_pos); | 124 void SetFrameAvoidingMouse(NSRect window_frame, const gfx::Point& mouse_pos); |
| 121 | 125 |
| 122 // The factory used to generate weak pointers for the show and hide delay | 126 // The factory used to generate weak pointers for the show and hide delay |
| 123 // timers. | 127 // timers. |
| 124 base::WeakPtrFactory<StatusBubbleMac> timer_factory_; | 128 base::WeakPtrFactory<StatusBubbleMac> timer_factory_; |
| 125 | 129 |
| 126 // The factory used to generate weak pointers for the expansion delay timer. | 130 // The factory used to generate weak pointers for the expansion delay timer. |
| 127 base::WeakPtrFactory<StatusBubbleMac> expand_timer_factory_; | 131 base::WeakPtrFactory<StatusBubbleMac> expand_timer_factory_; |
| 128 | 132 |
| 133 // The factory used to generate weak pointers for the CAAnimation completion |
| 134 // handlers. |
| 135 base::WeakPtrFactory<StatusBubbleMac> completion_handler_factory_; |
| 136 |
| 129 // Calculate the appropriate frame for the status bubble window. If | 137 // Calculate the appropriate frame for the status bubble window. If |
| 130 // |expanded_width|, use entire width of parent frame. | 138 // |expanded_width|, use entire width of parent frame. |
| 131 NSRect CalculateWindowFrame(bool expanded_width); | 139 NSRect CalculateWindowFrame(bool expanded_width); |
| 132 | 140 |
| 133 // Returns the flags to be used to round the corners of the status bubble. | 141 // Returns the flags to be used to round the corners of the status bubble. |
| 134 // Before 10.7, windows have square bottom corners, but in 10.7, the bottom | 142 // Before 10.7, windows have square bottom corners, but in 10.7, the bottom |
| 135 // corners are rounded. This method considers the bubble's placement (as | 143 // corners are rounded. This method considers the bubble's placement (as |
| 136 // proposed in window_frame) relative to its parent window in determining | 144 // proposed in window_frame) relative to its parent window in determining |
| 137 // which flags to return. This function may choose to round any corner, | 145 // which flags to return. This function may choose to round any corner, |
| 138 // including top corners. Note that there may be other reasons that a | 146 // including top corners. Note that there may be other reasons that a |
| 139 // status bubble's corner may be rounded in addition to those dependent on | 147 // status bubble's corner may be rounded in addition to those dependent on |
| 140 // OS version, and flags will be set or unset elsewhere to address these | 148 // OS version, and flags will be set or unset elsewhere to address these |
| 141 // concerns. | 149 // concerns. |
| 142 unsigned long OSDependentCornerFlags(NSRect window_frame); | 150 unsigned long OSDependentCornerFlags(NSRect window_frame); |
| 143 | 151 |
| 144 // The window we attach ourselves to. | 152 // The window we attach ourselves to. |
| 145 NSWindow* parent_; // WEAK | 153 NSWindow* parent_; // WEAK |
| 146 | 154 |
| 147 // The object that we query about our vertical offset for positioning. | 155 // The object that we query about our vertical offset for positioning. |
| 148 id delegate_; // WEAK | 156 id delegate_; // WEAK |
| 149 | 157 |
| 150 // The window we own. | 158 // The window we own. |
| 151 NSWindow* window_; | 159 StatusBubbleWindow* window_; |
| 152 | 160 |
| 153 // The status text we want to display when there are no URLs to display. | 161 // The status text we want to display when there are no URLs to display. |
| 154 NSString* status_text_; | 162 NSString* status_text_; |
| 155 | 163 |
| 156 // The url we want to display when there is no status text to display. | 164 // The url we want to display when there is no status text to display. |
| 157 NSString* url_text_; | 165 NSString* url_text_; |
| 158 | 166 |
| 159 // The status bubble's current state. Do not write to this field directly; | 167 // The status bubble's current state. Do not write to this field directly; |
| 160 // use SetState(). | 168 // use SetState(). |
| 161 StatusBubbleState state_; | 169 StatusBubbleState state_; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 184 @interface NSObject(StatusBubbleDelegate) | 192 @interface NSObject(StatusBubbleDelegate) |
| 185 // Called to query the delegate about the frame StatusBubble should position | 193 // Called to query the delegate about the frame StatusBubble should position |
| 186 // itself in. Frame is returned in the parent window coordinates. | 194 // itself in. Frame is returned in the parent window coordinates. |
| 187 - (NSRect)statusBubbleBaseFrame; | 195 - (NSRect)statusBubbleBaseFrame; |
| 188 | 196 |
| 189 // Called from SetState to notify the delegate of state changes. | 197 // Called from SetState to notify the delegate of state changes. |
| 190 - (void)statusBubbleWillEnterState:(StatusBubbleMac::StatusBubbleState)state; | 198 - (void)statusBubbleWillEnterState:(StatusBubbleMac::StatusBubbleState)state; |
| 191 @end | 199 @end |
| 192 | 200 |
| 193 #endif // CHROME_BROWSER_UI_COCOA_STATUS_BUBBLE_MAC_H_ | 201 #endif // CHROME_BROWSER_UI_COCOA_STATUS_BUBBLE_MAC_H_ |
| OLD | NEW |