OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 the Speech and BiDi submenu for the |
| 17 // context menu. |
| 18 // TODO(spqchan): Create a test suite for the Speech API. |
| 19 class UI_BASE_EXPORT TextServicesContextMenu |
| 20 : public SimpleMenuModel::Delegate { |
| 21 public: |
| 22 class UI_BASE_EXPORT Delegate { |
| 23 public: |
| 24 // Returns the selected text. |
| 25 virtual base::string16 GetSelectedText() const = 0; |
| 26 |
| 27 // Returns true if |direction| should be enabled in the BiDi submenu. |
| 28 virtual bool IsTextDirectionEnabled( |
| 29 base::i18n::TextDirection direction) const = 0; |
| 30 |
| 31 // Returns true if |direction| should be checked in the BiDi submenu. |
| 32 virtual bool IsTextDirectionChecked( |
| 33 base::i18n::TextDirection direction) const = 0; |
| 34 |
| 35 // Updates the text direction to |direction|. |
| 36 virtual void UpdateTextDirection(base::i18n::TextDirection direction) = 0; |
| 37 }; |
| 38 |
| 39 explicit TextServicesContextMenu(Delegate* delegate); |
| 40 |
| 41 // Methods for speaking. |
| 42 static void SpeakText(const base::string16& text); |
| 43 static void StopSpeaking(); |
| 44 static bool IsSpeaking(); |
| 45 |
| 46 // Appends general items to the context menu. |
| 47 void AppendToContextMenu(SimpleMenuModel* model); |
| 48 |
| 49 // Appends items to the context menu applicable to editable content. |
| 50 void AppendEditableItems(SimpleMenuModel* model); |
| 51 |
| 52 // SimpleMenuModel::Delegate: |
| 53 bool IsCommandIdChecked(int command_id) const override; |
| 54 bool IsCommandIdEnabled(int command_id) const override; |
| 55 void ExecuteCommand(int command_id, int event_flags) override; |
| 56 |
| 57 private: |
| 58 // Model for the "Speech" submenu. |
| 59 ui::SimpleMenuModel speech_submenu_model_; |
| 60 |
| 61 // Model for the BiDi input submenu. |
| 62 ui::SimpleMenuModel bidi_submenu_model_; |
| 63 |
| 64 Delegate* delegate_; // Weak. |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(TextServicesContextMenu); |
| 67 }; |
| 68 |
| 69 } // namespace ui |
| 70 |
| 71 #endif // UI_BASE_COCOA_TEXT_SERVICES_CONTEXT_MENU_H_ |
OLD | NEW |