Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2006 The Android Open Source Project |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | #ifndef SkOSMenu_DEFINED |
michael@0 | 11 | #define SkOSMenu_DEFINED |
michael@0 | 12 | |
michael@0 | 13 | #include "SkEvent.h" |
michael@0 | 14 | #include "SkTDArray.h" |
michael@0 | 15 | |
michael@0 | 16 | class SkOSMenu { |
michael@0 | 17 | public: |
michael@0 | 18 | explicit SkOSMenu(const char title[] = ""); |
michael@0 | 19 | ~SkOSMenu(); |
michael@0 | 20 | |
michael@0 | 21 | /** |
michael@0 | 22 | * Each of these (except action) has an associated value, which is stored in |
michael@0 | 23 | * the event payload for the item. |
michael@0 | 24 | * Each type has a specific type for its value... |
michael@0 | 25 | * Action : none |
michael@0 | 26 | * List : int (selected index) |
michael@0 | 27 | * Segmented : int (selected index) |
michael@0 | 28 | * Slider : float |
michael@0 | 29 | * Switch : bool |
michael@0 | 30 | * TextField : string |
michael@0 | 31 | * TriState : TriState |
michael@0 | 32 | * Custom : custom object/value |
michael@0 | 33 | */ |
michael@0 | 34 | enum Type { |
michael@0 | 35 | kAction_Type, |
michael@0 | 36 | kList_Type, |
michael@0 | 37 | kSlider_Type, |
michael@0 | 38 | kSwitch_Type, |
michael@0 | 39 | kTriState_Type, |
michael@0 | 40 | kTextField_Type, |
michael@0 | 41 | kCustom_Type |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | enum TriState { |
michael@0 | 45 | kMixedState = -1, |
michael@0 | 46 | kOffState = 0, |
michael@0 | 47 | kOnState = 1 |
michael@0 | 48 | }; |
michael@0 | 49 | |
michael@0 | 50 | class Item { |
michael@0 | 51 | public: |
michael@0 | 52 | /** |
michael@0 | 53 | * Auto increments a global to generate an unique ID for each new item |
michael@0 | 54 | * Note: Thread safe |
michael@0 | 55 | */ |
michael@0 | 56 | Item(const char label[], SkOSMenu::Type type, const char slotName[], |
michael@0 | 57 | SkEvent* evt); |
michael@0 | 58 | ~Item() { delete fEvent; } |
michael@0 | 59 | |
michael@0 | 60 | SkEvent* getEvent() const { return fEvent; } |
michael@0 | 61 | int getID() const { return fID; } |
michael@0 | 62 | const char* getLabel() const { return fLabel.c_str(); } |
michael@0 | 63 | const char* getSlotName() const { return fSlotName.c_str(); } |
michael@0 | 64 | Type getType() const { return fType; } |
michael@0 | 65 | void setKeyEquivalent(SkUnichar key) { fKey = key; } |
michael@0 | 66 | SkUnichar getKeyEquivalent() const { return fKey; } |
michael@0 | 67 | |
michael@0 | 68 | /** |
michael@0 | 69 | * Helper functions for predefined types |
michael@0 | 70 | */ |
michael@0 | 71 | void setBool(bool value) const; //For Switch |
michael@0 | 72 | void setScalar(SkScalar value) const; //For Slider |
michael@0 | 73 | void setInt(int value) const; //For List |
michael@0 | 74 | void setTriState(TriState value) const; //For Tristate |
michael@0 | 75 | void setString(const char value[]) const; //For TextField |
michael@0 | 76 | |
michael@0 | 77 | /** |
michael@0 | 78 | * Post event associated with the menu item to target, any changes to |
michael@0 | 79 | * the associated event must be made prior to calling this method |
michael@0 | 80 | */ |
michael@0 | 81 | void postEvent() const { (new SkEvent(*(fEvent)))->post(); } |
michael@0 | 82 | |
michael@0 | 83 | private: |
michael@0 | 84 | int fID; |
michael@0 | 85 | SkEvent* fEvent; |
michael@0 | 86 | SkString fLabel; |
michael@0 | 87 | SkString fSlotName; |
michael@0 | 88 | Type fType; |
michael@0 | 89 | SkUnichar fKey; |
michael@0 | 90 | }; |
michael@0 | 91 | |
michael@0 | 92 | void reset(); |
michael@0 | 93 | const char* getTitle() const { return fTitle.c_str(); } |
michael@0 | 94 | void setTitle (const char title[]) { fTitle.set(title); } |
michael@0 | 95 | int getCount() const { return fItems.count(); } |
michael@0 | 96 | const Item* getItemByID(int itemID) const; |
michael@0 | 97 | void getItems(const Item* items[]) const; |
michael@0 | 98 | |
michael@0 | 99 | /** |
michael@0 | 100 | * Assign key to the menu item with itemID, will do nothing if there's no |
michael@0 | 101 | * item with the id given |
michael@0 | 102 | */ |
michael@0 | 103 | void assignKeyEquivalentToItem(int itemID, SkUnichar key); |
michael@0 | 104 | /** |
michael@0 | 105 | * Call this in a SkView's onHandleChar to trigger any menu items with the |
michael@0 | 106 | * given key equivalent. If such an item is found, the method will return |
michael@0 | 107 | * true and its corresponding event will be triggered (default behavior |
michael@0 | 108 | * defined for switches(toggling), tristates(cycle), and lists(cycle), |
michael@0 | 109 | * for anything else, the event attached is posted without state changes) |
michael@0 | 110 | * If no menu item can be matched with the key, false will be returned |
michael@0 | 111 | */ |
michael@0 | 112 | bool handleKeyEquivalent(SkUnichar key); |
michael@0 | 113 | |
michael@0 | 114 | /** |
michael@0 | 115 | * The following functions append new items to the menu and returns their |
michael@0 | 116 | * associated unique id, which can be used to by the client to refer to |
michael@0 | 117 | * the menu item created and change its state. slotName specifies the string |
michael@0 | 118 | * identifier of any state/value to be returned in the item's SkEvent object |
michael@0 | 119 | * NOTE: evt must be dynamically allocated |
michael@0 | 120 | */ |
michael@0 | 121 | int appendItem(const char label[], Type type, const char slotName[], |
michael@0 | 122 | SkEvent* evt); |
michael@0 | 123 | |
michael@0 | 124 | /** |
michael@0 | 125 | * Create predefined items with the given parameters. To be used with the |
michael@0 | 126 | * other helper functions below to retrive/update state information. |
michael@0 | 127 | * Note: the helper functions below assume that slotName is UNIQUE for all |
michael@0 | 128 | * menu items of the same type since it's used to identify the event |
michael@0 | 129 | */ |
michael@0 | 130 | int appendAction(const char label[], SkEventSinkID target); |
michael@0 | 131 | int appendList(const char label[], const char slotName[], |
michael@0 | 132 | SkEventSinkID target, int defaultIndex, const char[] ...); |
michael@0 | 133 | int appendSlider(const char label[], const char slotName[], |
michael@0 | 134 | SkEventSinkID target, SkScalar min, SkScalar max, |
michael@0 | 135 | SkScalar defaultValue); |
michael@0 | 136 | int appendSwitch(const char label[], const char slotName[], |
michael@0 | 137 | SkEventSinkID target, bool defaultState = false); |
michael@0 | 138 | int appendTriState(const char label[], const char slotName[], |
michael@0 | 139 | SkEventSinkID target, TriState defaultState = kOffState); |
michael@0 | 140 | int appendTextField(const char label[], const char slotName[], |
michael@0 | 141 | SkEventSinkID target, const char placeholder[] = ""); |
michael@0 | 142 | |
michael@0 | 143 | |
michael@0 | 144 | /** |
michael@0 | 145 | * Helper functions to retrieve information other than the stored value for |
michael@0 | 146 | * some predefined types |
michael@0 | 147 | */ |
michael@0 | 148 | static bool FindListItemCount(const SkEvent& evt, int* count); |
michael@0 | 149 | /** |
michael@0 | 150 | * Ensure that the items array can store n SkStrings where n is the count |
michael@0 | 151 | * extracted using FindListItemCount |
michael@0 | 152 | */ |
michael@0 | 153 | static bool FindListItems(const SkEvent& evt, SkString items[]); |
michael@0 | 154 | static bool FindSliderMin(const SkEvent& evt, SkScalar* min); |
michael@0 | 155 | static bool FindSliderMax(const SkEvent& evt, SkScalar* max); |
michael@0 | 156 | |
michael@0 | 157 | /** |
michael@0 | 158 | * Returns true if an action with the given label is found, false otherwise |
michael@0 | 159 | */ |
michael@0 | 160 | static bool FindAction(const SkEvent& evt, const char label[]); |
michael@0 | 161 | /** |
michael@0 | 162 | * The following helper functions will return true if evt is generated from |
michael@0 | 163 | * a predefined item type and retrieve the corresponding state information. |
michael@0 | 164 | * They will return false and leave value unchanged if there's a type |
michael@0 | 165 | * mismatch or slotName is incorrect |
michael@0 | 166 | */ |
michael@0 | 167 | static bool FindListIndex(const SkEvent& evt, const char slotName[], int* value); |
michael@0 | 168 | static bool FindSliderValue(const SkEvent& evt, const char slotName[], SkScalar* value); |
michael@0 | 169 | static bool FindSwitchState(const SkEvent& evt, const char slotName[], bool* value); |
michael@0 | 170 | static bool FindTriState(const SkEvent& evt, const char slotName[], TriState* value); |
michael@0 | 171 | static bool FindText(const SkEvent& evt, const char slotName[], SkString* value); |
michael@0 | 172 | |
michael@0 | 173 | private: |
michael@0 | 174 | SkString fTitle; |
michael@0 | 175 | SkTDArray<Item*> fItems; |
michael@0 | 176 | |
michael@0 | 177 | // illegal |
michael@0 | 178 | SkOSMenu(const SkOSMenu&); |
michael@0 | 179 | SkOSMenu& operator=(const SkOSMenu&); |
michael@0 | 180 | }; |
michael@0 | 181 | |
michael@0 | 182 | #endif |