Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: chrome/browser/cocoa/status_bubble_mac.h

Issue 269045: Mac status bubble delays and fades (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/cocoa/status_bubble_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_COCOA_STATUS_BUBBLE_MAC_H_ 5 #ifndef CHROME_BROWSER_COCOA_STATUS_BUBBLE_MAC_H_
6 #define CHROME_BROWSER_COCOA_STATUS_BUBBLE_MAC_H_ 6 #define CHROME_BROWSER_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 12
13 #include "base/task.h"
12 #include "chrome/browser/status_bubble.h" 14 #include "chrome/browser/status_bubble.h"
13 15
14 class GURL; 16 class GURL;
15 class StatusBubbleMacTest; 17 class StatusBubbleMacTest;
16 18
17 class StatusBubbleMac : public StatusBubble { 19 class StatusBubbleMac : public StatusBubble {
18 public: 20 public:
21 // The various states that a status bubble may be in. Public for delegate
22 // access (for testing).
23 enum StatusBubbleState {
24 kBubbleHidden, // Fully hidden
25 kBubbleShowingTimer, // Waiting to fade in
26 kBubbleShowingFadeIn, // In a fade-in transition
27 kBubbleShown, // Fully visible
28 kBubbleHidingTimer, // Waiting to fade out
29 kBubbleHidingFadeOut // In a fade-out transition
30 };
31
19 StatusBubbleMac(NSWindow* parent, id delegate); 32 StatusBubbleMac(NSWindow* parent, id delegate);
20 virtual ~StatusBubbleMac(); 33 virtual ~StatusBubbleMac();
21 34
22 // StatusBubble implementation. 35 // StatusBubble implementation.
23 virtual void SetStatus(const std::wstring& status); 36 virtual void SetStatus(const std::wstring& status);
24 virtual void SetURL(const GURL& url, const std::wstring& languages); 37 virtual void SetURL(const GURL& url, const std::wstring& languages);
25 virtual void Hide(); 38 virtual void Hide();
26 virtual void MouseMoved(); 39 virtual void MouseMoved();
27 virtual void UpdateDownloadShelfVisibility(bool visible); 40 virtual void UpdateDownloadShelfVisibility(bool visible);
28 41
29 // Mac-specific method: Update the size and position of the status bubble to 42 // Mac-specific method: Update the size and position of the status bubble to
30 // match the parent window. Safe to call even when the status bubble does not 43 // match the parent window. Safe to call even when the status bubble does not
31 // exist. 44 // exist.
32 void UpdateSizeAndPosition(); 45 void UpdateSizeAndPosition();
33 46
47 // Delegate method called when a fade-in or fade-out transition has
48 // completed. This is public so that it may be visible to the CAAnimation
49 // delegate, which is an Objective-C object.
50 void AnimationDidStop(CAAnimation* animation, bool finished);
51
34 private: 52 private:
35 friend class StatusBubbleMacTest; 53 friend class StatusBubbleMacTest;
36 54
37 void SetStatus(NSString* status, bool is_url); 55 // Setter for state_. Use this instead of writing to state_ directly so
56 // that state changes can be observed by unit tests.
57 void SetState(StatusBubbleState state);
58
59 // Sets the bubble text for SetStatus and SetURL.
60 void SetText(const std::wstring& text, bool is_url);
38 61
39 // Construct the window/widget if it does not already exist. (Safe to call if 62 // Construct the window/widget if it does not already exist. (Safe to call if
40 // it does.) 63 // it does.)
41 void Create(); 64 void Create();
42 65
43 void FadeIn(); 66 // Attaches the status bubble window to its parent window.
44 void FadeOut(); 67 void Attach();
68
69 // Begins fading the status bubble window in or out depending on the value
70 // of |show|. This must be called from the appropriate fade state,
71 // kBubbleShowingFadeIn or kBubbleHidingFadeOut, or from the appropriate
72 // fully-shown/hidden state, kBubbleShown or kBubbleHidden. This may be
73 // called at any point during a fade-in or fade-out; it is even possible to
74 // reverse a transition before it has completed.
75 void Fade(bool show);
76
77 // One-shot timer operations to manage the delays associated with the
78 // kBubbleShowingTimer and kBubbleHidingTimer states. StartTimer and
79 // TimerFired must be called from one of these states. StartTimer may be
80 // called while the timer is still running; in that case, the timer will be
81 // reset. CancelTimer may be called from any state.
82 void StartTimer(int64 time_ms);
83 void CancelTimer();
84 void TimerFired();
85
86 // Begin the process of showing or hiding the status bubble. These may be
87 // called from any state, and will take the appropriate action to initiate
88 // any state changes that may be needed.
89 void StartShowing();
90 void StartHiding();
91
92 // The timer factory used for show and hide delay timers.
93 ScopedRunnableMethodFactory<StatusBubbleMac> timer_factory_;
45 94
46 // Calculate the appropriate frame for the status bubble window. 95 // Calculate the appropriate frame for the status bubble window.
47 NSRect CalculateWindowFrame(); 96 NSRect CalculateWindowFrame();
48 97
49 // The window we attach ourselves to. 98 // The window we attach ourselves to.
50 NSWindow* parent_; // WEAK 99 NSWindow* parent_; // WEAK
51 100
52 // The object that we query about our vertical offset for positioning. 101 // The object that we query about our vertical offset for positioning.
53 id delegate_; // WEAK 102 id delegate_; // WEAK
54 103
55 // The window we own. 104 // The window we own.
56 NSWindow* window_; 105 NSWindow* window_;
57 106
58 // The status text we want to display when there are no URLs to display. 107 // The status text we want to display when there are no URLs to display.
59 NSString* status_text_; 108 NSString* status_text_;
60 109
61 // The url we want to display when there is no status text to display. 110 // The url we want to display when there is no status text to display.
62 NSString* url_text_; 111 NSString* url_text_;
63 112
64 // How vertically offset the bubble is from its root position. 113 // The status bubble's current state. Do not write to this field directly;
65 int offset_; 114 // use SetState().
115 StatusBubbleState state_;
116
117 // True if operations are to be performed immediately rather than waiting
118 // for delays and transitions. Normally false, this should only be set to
119 // true for testing.
120 bool immediate_;
121
122 DISALLOW_COPY_AND_ASSIGN(StatusBubbleMac);
66 }; 123 };
67 124
68 // Delegate interface that allows the StatusBubble to query its delegate about 125 // Delegate interface
69 // the vertical offset (if any) that should be applied to the StatusBubble's
70 // position.
71 @interface NSObject(StatusBubbleDelegate) 126 @interface NSObject(StatusBubbleDelegate)
127 // Called to query the delegate about the vertical offset (if any) that should
128 // be applied to the StatusBubble's position.
72 - (float)verticalOffsetForStatusBubble; 129 - (float)verticalOffsetForStatusBubble;
130
131 // Called from SetState to notify the delegate of state changes.
132 - (void)statusBubbleWillEnterState:(StatusBubbleMac::StatusBubbleState)state;
73 @end 133 @end
74 134
75 #endif // #ifndef CHROME_BROWSER_COCOA_STATUS_BUBBLE_MAC_H_ 135 #endif // #ifndef CHROME_BROWSER_COCOA_STATUS_BUBBLE_MAC_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/cocoa/status_bubble_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698