OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef UI_BASE_COCOA_TEXT_SERVICES_CONTEXT_MENU_H_ |
| 6 #define UI_BASE_COCOA_TEXT_SERVICES_CONTEXT_MENU_H_ |
| 7 |
| 8 #include "base/i18n/rtl.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/strings/string16.h" |
| 11 #include "ui/base/models/simple_menu_model.h" |
| 12 #include "ui/base/ui_base_export.h" |
| 13 |
| 14 namespace ui { |
| 15 |
| 16 // This class is used to append and handle text service items to the context |
| 17 // menu. These items are comprised of the Speech, Look Up, and BiDi items. |
| 18 class UI_BASE_EXPORT TextServicesContextMenu |
| 19 : public SimpleMenuModel::Delegate { |
| 20 public: |
| 21 class UI_BASE_EXPORT Delegate { |
| 22 public: |
| 23 // Returns the selected text. |
| 24 virtual base::string16 GetSelectedText() const = 0; |
| 25 |
| 26 // Handles the "Start Speaking" command. The delegate is expected to |
| 27 // provide text and call SpeakText(). |
| 28 virtual void OnSpeakRequested() = 0; |
| 29 |
| 30 // Returns true if the "Look Up" item is available on the menu. |
| 31 virtual bool IsLookUpAvailable() const = 0; |
| 32 |
| 33 // Handles the "Look Up" command. |
| 34 virtual void LookUpInDictionary() = 0; |
| 35 |
| 36 // Returns true if |direction| should be enabled in the BiDi submenu. |
| 37 virtual bool IsTextDirectionEnabled( |
| 38 base::i18n::TextDirection direction) const = 0; |
| 39 |
| 40 // Returns true if |direction| should be checked in the BiDi submenu. |
| 41 virtual bool IsTextDirectionChecked( |
| 42 base::i18n::TextDirection direction) const = 0; |
| 43 |
| 44 // Updates the text direction to |direction|. |
| 45 virtual void UpdateTextDirection(base::i18n::TextDirection direction) = 0; |
| 46 }; |
| 47 |
| 48 explicit TextServicesContextMenu(Delegate* delegate); |
| 49 |
| 50 // Methods for speaking. |
| 51 static void SpeakText(const base::string16& text); |
| 52 static void StopSpeaking(); |
| 53 static bool IsSpeaking(); |
| 54 |
| 55 // Appends general items to the context menu. |
| 56 void AppendToContextMenu(SimpleMenuModel* model); |
| 57 |
| 58 // Appends editable items to the context menu. |
| 59 void AppendEditableItems(SimpleMenuModel* model); |
| 60 |
| 61 // Returns true if the command_id is supported by the text services menu. |
| 62 bool IsTextServicesCommandId(int command_id) const; |
| 63 |
| 64 // SimpleMenuModel::Delegate: |
| 65 void ExecuteCommand(int command_id, int event_flags) override; |
| 66 bool IsCommandIdChecked(int command_id) const override; |
| 67 bool IsCommandIdEnabled(int command_id) const override; |
| 68 |
| 69 private: |
| 70 // Model for the "Speech" submenu. |
| 71 ui::SimpleMenuModel speech_submenu_model_; |
| 72 |
| 73 // Model for the BiDi input submenu. |
| 74 ui::SimpleMenuModel bidi_submenu_model_; |
| 75 |
| 76 Delegate* delegate_; // Weak. |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(TextServicesContextMenu); |
| 79 }; |
| 80 |
| 81 } // namespace ui |
| 82 |
| 83 #endif // UI_BASE_COCOA_TEXT_SERVICES_CONTEXT_MENU_H_ |
OLD | NEW |