Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #ifndef UserGestureIndicator_h | 26 #ifndef UserGestureIndicator_h |
| 27 #define UserGestureIndicator_h | 27 #define UserGestureIndicator_h |
| 28 | 28 |
| 29 #include "platform/PlatformExport.h" | 29 #include "platform/PlatformExport.h" |
| 30 #include "wtf/Noncopyable.h" | 30 #include "wtf/Noncopyable.h" |
| 31 #include "wtf/RefCounted.h" | 31 #include "wtf/RefCounted.h" |
| 32 #include "wtf/RefPtr.h" | 32 #include "wtf/RefPtr.h" |
| 33 | 33 |
| 34 namespace blink { | 34 namespace blink { |
| 35 | 35 |
| 36 enum ProcessingUserGestureState { | |
| 37 DefinitelyProcessingNewUserGesture, | |
| 38 DefinitelyProcessingUserGesture, | |
| 39 PossiblyProcessingUserGesture, | |
| 40 DefinitelyNotProcessingUserGesture | |
| 41 }; | |
| 42 | |
| 43 class PLATFORM_EXPORT UserGestureToken : public RefCounted<UserGestureToken> { | |
| 44 WTF_MAKE_NONCOPYABLE(UserGestureToken); | |
| 45 | |
| 46 public: | |
| 47 UserGestureToken() {} | |
| 48 virtual ~UserGestureToken() {} | |
| 49 virtual bool hasGestures() const = 0; | |
| 50 virtual void setOutOfProcess() = 0; | |
| 51 virtual void setJavascriptPrompt() = 0; | |
| 52 virtual void setPauseInDebugger() = 0; | |
| 53 }; | |
| 54 | |
| 55 // Callback to be invoked when the state of a UserGestureIndicator is | 36 // Callback to be invoked when the state of a UserGestureIndicator is |
| 56 // used (only during the scope of a UserGestureIndicator, does | 37 // used (only during the scope of a UserGestureIndicator, does |
| 57 // not flow with the UserGestureToken). It's the responsibility of the | 38 // not flow with the UserGestureToken). It's the responsibility of the |
| 58 // caller to ensure the UserGestureUtilizedCallback is kept alive as long | 39 // caller to ensure the UserGestureUtilizedCallback is kept alive as long |
| 59 // as the UserGestureIndicator it's used in. | 40 // as the UserGestureIndicator it's used in. |
| 60 // Note that this doesn't currently track EVERY way in which the | 41 // Note that this doesn't currently track EVERY way in which the |
| 61 // state of a UserGesture can be read (sometimes it's just propagated | 42 // state of a UserGesture can be read (sometimes it's just propagated |
| 62 // elsewhere, or otherwise read in a way that's hard to know if it will | 43 // elsewhere, or otherwise read in a way that's hard to know if it will |
| 63 // actually be used), but should include the primary use cases. Therefore | 44 // actually be used), but should include the primary use cases. Therefore |
| 64 // this is suitable mainly for diagnostics and measurement purposes. | 45 // this is suitable mainly for diagnostics and measurement purposes. |
| 65 class PLATFORM_EXPORT UserGestureUtilizedCallback { | 46 class PLATFORM_EXPORT UserGestureUtilizedCallback { |
| 66 public: | 47 public: |
| 67 virtual ~UserGestureUtilizedCallback() = default; | 48 virtual ~UserGestureUtilizedCallback() = default; |
| 68 virtual void userGestureUtilized() = 0; | 49 virtual void userGestureUtilized() = 0; |
| 69 }; | 50 }; |
| 70 | 51 |
| 52 class PLATFORM_EXPORT UserGestureToken : public RefCounted<UserGestureToken> { | |
|
Rick Byers
2016/10/11 18:00:19
nit: since you're overhauling this, can you please
Nate Chapin
2016/10/11 19:17:55
Done.
| |
| 53 WTF_MAKE_NONCOPYABLE(UserGestureToken); | |
| 54 | |
| 55 public: | |
| 56 enum Status { NewGesture, PossiblyExistingGesture }; | |
| 57 enum TimeoutPolicy { Default, OutOfProcess, HasPaused }; | |
| 58 | |
| 59 static PassRefPtr<UserGestureToken> create( | |
| 60 Status status = PossiblyExistingGesture) { | |
| 61 return adoptRef(new UserGestureToken(status)); | |
| 62 } | |
| 63 | |
| 64 ~UserGestureToken() {} | |
| 65 bool hasGestures(); | |
| 66 void transferGestureTo(UserGestureToken*); | |
| 67 bool consumeGesture(); | |
| 68 void setTimeoutPolicy(TimeoutPolicy); | |
| 69 void setUserGestureUtilizedCallback(UserGestureUtilizedCallback*); | |
|
Rick Byers
2016/10/11 18:00:19
Add a comment describing the lifetime semantics fo
Nate Chapin
2016/10/11 19:17:55
Done.
| |
| 70 void userGestureUtilized(); | |
| 71 | |
| 72 private: | |
| 73 UserGestureToken(Status); | |
| 74 | |
| 75 bool hasTimedOut() const; | |
| 76 | |
| 77 size_t m_consumableGestures; | |
| 78 double m_timestamp; | |
| 79 TimeoutPolicy m_timeoutPolicy; | |
| 80 UserGestureUtilizedCallback* m_usageCallback; | |
| 81 }; | |
| 82 | |
| 71 class PLATFORM_EXPORT UserGestureIndicator final { | 83 class PLATFORM_EXPORT UserGestureIndicator final { |
| 72 USING_FAST_MALLOC(UserGestureIndicator); | 84 USING_FAST_MALLOC(UserGestureIndicator); |
| 73 WTF_MAKE_NONCOPYABLE(UserGestureIndicator); | 85 WTF_MAKE_NONCOPYABLE(UserGestureIndicator); |
| 74 | 86 |
| 75 public: | 87 public: |
| 76 // Returns whether a user gesture is currently in progress. | 88 // Returns whether a user gesture is currently in progress. |
| 77 // Does not invoke the UserGestureUtilizedCallback. Consider calling | 89 // Does not invoke the UserGestureUtilizedCallback. Consider calling |
| 78 // utilizeUserGesture instead if you know for sure that the return value | 90 // utilizeUserGesture instead if you know for sure that the return value |
| 79 // will have an effect. | 91 // will have an effect. |
| 80 static bool processingUserGesture(); | 92 static bool processingUserGesture(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 92 static bool consumeUserGesture(); | 104 static bool consumeUserGesture(); |
| 93 | 105 |
| 94 static UserGestureToken* currentToken(); | 106 static UserGestureToken* currentToken(); |
| 95 | 107 |
| 96 // Reset the notion of "since load". | 108 // Reset the notion of "since load". |
| 97 static void clearProcessedUserGestureSinceLoad(); | 109 static void clearProcessedUserGestureSinceLoad(); |
| 98 | 110 |
| 99 // Returns whether a user gesture has occurred since page load. | 111 // Returns whether a user gesture has occurred since page load. |
| 100 static bool processedUserGestureSinceLoad(); | 112 static bool processedUserGestureSinceLoad(); |
| 101 | 113 |
| 102 explicit UserGestureIndicator(ProcessingUserGestureState, | 114 explicit UserGestureIndicator(PassRefPtr<UserGestureToken>); |
| 103 UserGestureUtilizedCallback* = 0); | |
| 104 explicit UserGestureIndicator(PassRefPtr<UserGestureToken>, | |
| 105 UserGestureUtilizedCallback* = 0); | |
| 106 ~UserGestureIndicator(); | 115 ~UserGestureIndicator(); |
| 107 | 116 |
| 108 private: | 117 private: |
| 109 static ProcessingUserGestureState s_state; | |
| 110 static UserGestureIndicator* s_topmostIndicator; | |
| 111 static bool s_processedUserGestureSinceLoad; | 118 static bool s_processedUserGestureSinceLoad; |
| 112 ProcessingUserGestureState m_previousState; | 119 static UserGestureToken* s_rootToken; |
| 120 | |
| 113 RefPtr<UserGestureToken> m_token; | 121 RefPtr<UserGestureToken> m_token; |
| 114 UserGestureUtilizedCallback* m_usageCallback; | |
| 115 }; | 122 }; |
| 116 | 123 |
| 117 } // namespace blink | 124 } // namespace blink |
| 118 | 125 |
| 119 #endif | 126 #endif |
| OLD | NEW |