Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2010 The Android Open Source Project |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #ifndef _UI_POINTER_CONTROLLER_H |
michael@0 | 18 | #define _UI_POINTER_CONTROLLER_H |
michael@0 | 19 | |
michael@0 | 20 | #include "SpriteController.h" |
michael@0 | 21 | |
michael@0 | 22 | #include <ui/DisplayInfo.h> |
michael@0 | 23 | #include "Input.h" |
michael@0 | 24 | #include <utils/BitSet.h> |
michael@0 | 25 | #include <utils/RefBase.h> |
michael@0 | 26 | #include <utils/Looper.h> |
michael@0 | 27 | #include <utils/String8.h> |
michael@0 | 28 | |
michael@0 | 29 | #include <SkBitmap.h> |
michael@0 | 30 | |
michael@0 | 31 | namespace android { |
michael@0 | 32 | |
michael@0 | 33 | /** |
michael@0 | 34 | * Interface for tracking a mouse / touch pad pointer and touch pad spots. |
michael@0 | 35 | * |
michael@0 | 36 | * The spots are sprites on screen that visually represent the positions of |
michael@0 | 37 | * fingers |
michael@0 | 38 | * |
michael@0 | 39 | * The pointer controller is responsible for providing synchronization and for tracking |
michael@0 | 40 | * display orientation changes if needed. |
michael@0 | 41 | */ |
michael@0 | 42 | class PointerControllerInterface : public virtual RefBase { |
michael@0 | 43 | protected: |
michael@0 | 44 | PointerControllerInterface() { } |
michael@0 | 45 | virtual ~PointerControllerInterface() { } |
michael@0 | 46 | |
michael@0 | 47 | public: |
michael@0 | 48 | /* Gets the bounds of the region that the pointer can traverse. |
michael@0 | 49 | * Returns true if the bounds are available. */ |
michael@0 | 50 | virtual bool getBounds(float* outMinX, float* outMinY, |
michael@0 | 51 | float* outMaxX, float* outMaxY) const = 0; |
michael@0 | 52 | |
michael@0 | 53 | /* Move the pointer. */ |
michael@0 | 54 | virtual void move(float deltaX, float deltaY) = 0; |
michael@0 | 55 | |
michael@0 | 56 | /* Sets a mask that indicates which buttons are pressed. */ |
michael@0 | 57 | virtual void setButtonState(int32_t buttonState) = 0; |
michael@0 | 58 | |
michael@0 | 59 | /* Gets a mask that indicates which buttons are pressed. */ |
michael@0 | 60 | virtual int32_t getButtonState() const = 0; |
michael@0 | 61 | |
michael@0 | 62 | /* Sets the absolute location of the pointer. */ |
michael@0 | 63 | virtual void setPosition(float x, float y) = 0; |
michael@0 | 64 | |
michael@0 | 65 | /* Gets the absolute location of the pointer. */ |
michael@0 | 66 | virtual void getPosition(float* outX, float* outY) const = 0; |
michael@0 | 67 | |
michael@0 | 68 | enum Transition { |
michael@0 | 69 | // Fade/unfade immediately. |
michael@0 | 70 | TRANSITION_IMMEDIATE, |
michael@0 | 71 | // Fade/unfade gradually. |
michael@0 | 72 | TRANSITION_GRADUAL, |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | /* Fades the pointer out now. */ |
michael@0 | 76 | virtual void fade(Transition transition) = 0; |
michael@0 | 77 | |
michael@0 | 78 | /* Makes the pointer visible if it has faded out. |
michael@0 | 79 | * The pointer never unfades itself automatically. This method must be called |
michael@0 | 80 | * by the client whenever the pointer is moved or a button is pressed and it |
michael@0 | 81 | * wants to ensure that the pointer becomes visible again. */ |
michael@0 | 82 | virtual void unfade(Transition transition) = 0; |
michael@0 | 83 | |
michael@0 | 84 | enum Presentation { |
michael@0 | 85 | // Show the mouse pointer. |
michael@0 | 86 | PRESENTATION_POINTER, |
michael@0 | 87 | // Show spots and a spot anchor in place of the mouse pointer. |
michael@0 | 88 | PRESENTATION_SPOT, |
michael@0 | 89 | }; |
michael@0 | 90 | |
michael@0 | 91 | /* Sets the mode of the pointer controller. */ |
michael@0 | 92 | virtual void setPresentation(Presentation presentation) = 0; |
michael@0 | 93 | |
michael@0 | 94 | /* Sets the spots for the current gesture. |
michael@0 | 95 | * The spots are not subject to the inactivity timeout like the pointer |
michael@0 | 96 | * itself it since they are expected to remain visible for so long as |
michael@0 | 97 | * the fingers are on the touch pad. |
michael@0 | 98 | * |
michael@0 | 99 | * The values of the AMOTION_EVENT_AXIS_PRESSURE axis is significant. |
michael@0 | 100 | * For spotCoords, pressure != 0 indicates that the spot's location is being |
michael@0 | 101 | * pressed (not hovering). |
michael@0 | 102 | */ |
michael@0 | 103 | virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, |
michael@0 | 104 | BitSet32 spotIdBits) = 0; |
michael@0 | 105 | |
michael@0 | 106 | /* Removes all spots. */ |
michael@0 | 107 | virtual void clearSpots() = 0; |
michael@0 | 108 | }; |
michael@0 | 109 | |
michael@0 | 110 | |
michael@0 | 111 | /* |
michael@0 | 112 | * Pointer resources. |
michael@0 | 113 | */ |
michael@0 | 114 | struct PointerResources { |
michael@0 | 115 | SpriteIcon spotHover; |
michael@0 | 116 | SpriteIcon spotTouch; |
michael@0 | 117 | SpriteIcon spotAnchor; |
michael@0 | 118 | }; |
michael@0 | 119 | |
michael@0 | 120 | |
michael@0 | 121 | /* |
michael@0 | 122 | * Pointer controller policy interface. |
michael@0 | 123 | * |
michael@0 | 124 | * The pointer controller policy is used by the pointer controller to interact with |
michael@0 | 125 | * the Window Manager and other system components. |
michael@0 | 126 | * |
michael@0 | 127 | * The actual implementation is partially supported by callbacks into the DVM |
michael@0 | 128 | * via JNI. This interface is also mocked in the unit tests. |
michael@0 | 129 | */ |
michael@0 | 130 | class PointerControllerPolicyInterface : public virtual RefBase { |
michael@0 | 131 | protected: |
michael@0 | 132 | PointerControllerPolicyInterface() { } |
michael@0 | 133 | virtual ~PointerControllerPolicyInterface() { } |
michael@0 | 134 | |
michael@0 | 135 | public: |
michael@0 | 136 | virtual void loadPointerResources(PointerResources* outResources) = 0; |
michael@0 | 137 | }; |
michael@0 | 138 | |
michael@0 | 139 | |
michael@0 | 140 | /* |
michael@0 | 141 | * Tracks pointer movements and draws the pointer sprite to a surface. |
michael@0 | 142 | * |
michael@0 | 143 | * Handles pointer acceleration and animation. |
michael@0 | 144 | */ |
michael@0 | 145 | class PointerController : public PointerControllerInterface, public MessageHandler { |
michael@0 | 146 | protected: |
michael@0 | 147 | virtual ~PointerController(); |
michael@0 | 148 | |
michael@0 | 149 | public: |
michael@0 | 150 | enum InactivityTimeout { |
michael@0 | 151 | INACTIVITY_TIMEOUT_NORMAL = 0, |
michael@0 | 152 | INACTIVITY_TIMEOUT_SHORT = 1, |
michael@0 | 153 | }; |
michael@0 | 154 | |
michael@0 | 155 | PointerController(const sp<PointerControllerPolicyInterface>& policy, |
michael@0 | 156 | const sp<Looper>& looper, const sp<SpriteController>& spriteController); |
michael@0 | 157 | |
michael@0 | 158 | virtual bool getBounds(float* outMinX, float* outMinY, |
michael@0 | 159 | float* outMaxX, float* outMaxY) const; |
michael@0 | 160 | virtual void move(float deltaX, float deltaY); |
michael@0 | 161 | virtual void setButtonState(int32_t buttonState); |
michael@0 | 162 | virtual int32_t getButtonState() const; |
michael@0 | 163 | virtual void setPosition(float x, float y); |
michael@0 | 164 | virtual void getPosition(float* outX, float* outY) const; |
michael@0 | 165 | virtual void fade(Transition transition); |
michael@0 | 166 | virtual void unfade(Transition transition); |
michael@0 | 167 | |
michael@0 | 168 | virtual void setPresentation(Presentation presentation); |
michael@0 | 169 | virtual void setSpots(const PointerCoords* spotCoords, |
michael@0 | 170 | const uint32_t* spotIdToIndex, BitSet32 spotIdBits); |
michael@0 | 171 | virtual void clearSpots(); |
michael@0 | 172 | |
michael@0 | 173 | void setDisplayViewport(int32_t width, int32_t height, int32_t orientation); |
michael@0 | 174 | void setPointerIcon(const SpriteIcon& icon); |
michael@0 | 175 | void setInactivityTimeout(InactivityTimeout inactivityTimeout); |
michael@0 | 176 | |
michael@0 | 177 | private: |
michael@0 | 178 | static const size_t MAX_RECYCLED_SPRITES = 12; |
michael@0 | 179 | static const size_t MAX_SPOTS = 12; |
michael@0 | 180 | |
michael@0 | 181 | enum { |
michael@0 | 182 | MSG_ANIMATE, |
michael@0 | 183 | MSG_INACTIVITY_TIMEOUT, |
michael@0 | 184 | }; |
michael@0 | 185 | |
michael@0 | 186 | struct Spot { |
michael@0 | 187 | static const uint32_t INVALID_ID = 0xffffffff; |
michael@0 | 188 | |
michael@0 | 189 | uint32_t id; |
michael@0 | 190 | sp<Sprite> sprite; |
michael@0 | 191 | float alpha; |
michael@0 | 192 | float scale; |
michael@0 | 193 | float x, y; |
michael@0 | 194 | |
michael@0 | 195 | inline Spot(uint32_t id, const sp<Sprite>& sprite) |
michael@0 | 196 | : id(id), sprite(sprite), alpha(1.0f), scale(1.0f), |
michael@0 | 197 | x(0.0f), y(0.0f), lastIcon(NULL) { } |
michael@0 | 198 | |
michael@0 | 199 | void updateSprite(const SpriteIcon* icon, float x, float y); |
michael@0 | 200 | |
michael@0 | 201 | private: |
michael@0 | 202 | const SpriteIcon* lastIcon; |
michael@0 | 203 | }; |
michael@0 | 204 | |
michael@0 | 205 | mutable Mutex mLock; |
michael@0 | 206 | |
michael@0 | 207 | sp<PointerControllerPolicyInterface> mPolicy; |
michael@0 | 208 | sp<Looper> mLooper; |
michael@0 | 209 | sp<SpriteController> mSpriteController; |
michael@0 | 210 | sp<WeakMessageHandler> mHandler; |
michael@0 | 211 | |
michael@0 | 212 | PointerResources mResources; |
michael@0 | 213 | |
michael@0 | 214 | struct Locked { |
michael@0 | 215 | bool animationPending; |
michael@0 | 216 | nsecs_t animationTime; |
michael@0 | 217 | |
michael@0 | 218 | int32_t displayWidth; |
michael@0 | 219 | int32_t displayHeight; |
michael@0 | 220 | int32_t displayOrientation; |
michael@0 | 221 | |
michael@0 | 222 | InactivityTimeout inactivityTimeout; |
michael@0 | 223 | |
michael@0 | 224 | Presentation presentation; |
michael@0 | 225 | bool presentationChanged; |
michael@0 | 226 | |
michael@0 | 227 | int32_t pointerFadeDirection; |
michael@0 | 228 | float pointerX; |
michael@0 | 229 | float pointerY; |
michael@0 | 230 | float pointerAlpha; |
michael@0 | 231 | sp<Sprite> pointerSprite; |
michael@0 | 232 | SpriteIcon pointerIcon; |
michael@0 | 233 | bool pointerIconChanged; |
michael@0 | 234 | |
michael@0 | 235 | int32_t buttonState; |
michael@0 | 236 | |
michael@0 | 237 | Vector<Spot*> spots; |
michael@0 | 238 | Vector<sp<Sprite> > recycledSprites; |
michael@0 | 239 | } mLocked; |
michael@0 | 240 | |
michael@0 | 241 | bool getBoundsLocked(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const; |
michael@0 | 242 | void setPositionLocked(float x, float y); |
michael@0 | 243 | |
michael@0 | 244 | void handleMessage(const Message& message); |
michael@0 | 245 | void doAnimate(); |
michael@0 | 246 | void doInactivityTimeout(); |
michael@0 | 247 | |
michael@0 | 248 | void startAnimationLocked(); |
michael@0 | 249 | |
michael@0 | 250 | void resetInactivityTimeoutLocked(); |
michael@0 | 251 | void removeInactivityTimeoutLocked(); |
michael@0 | 252 | void updatePointerLocked(); |
michael@0 | 253 | |
michael@0 | 254 | Spot* getSpotLocked(uint32_t id); |
michael@0 | 255 | Spot* createAndAddSpotLocked(uint32_t id); |
michael@0 | 256 | Spot* removeFirstFadingSpotLocked(); |
michael@0 | 257 | void releaseSpotLocked(Spot* spot); |
michael@0 | 258 | void fadeOutAndReleaseSpotLocked(Spot* spot); |
michael@0 | 259 | void fadeOutAndReleaseAllSpotsLocked(); |
michael@0 | 260 | |
michael@0 | 261 | void loadResources(); |
michael@0 | 262 | }; |
michael@0 | 263 | |
michael@0 | 264 | } // namespace android |
michael@0 | 265 | |
michael@0 | 266 | #endif // _UI_POINTER_CONTROLLER_H |