summaryrefslogtreecommitdiff
path: root/chromium/ui/base/cocoa/text_services_context_menu.h
blob: 2c163d7bee704c50e801411dced73824340f2b42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_BASE_COCOA_TEXT_SERVICES_CONTEXT_MENU_H_
#define UI_BASE_COCOA_TEXT_SERVICES_CONTEXT_MENU_H_

#include "base/i18n/rtl.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/ui_base_export.h"

namespace ui {

// This class is used to append and handle the Speech and BiDi submenu for the
// context menu.
// TODO (spqchan): Replace the Speech and BiDi logic in RenderViewContextMenu
// with TextServicesContextMenu.
class UI_BASE_EXPORT TextServicesContextMenu
    : public SimpleMenuModel::Delegate {
 public:
  class UI_BASE_EXPORT Delegate {
   public:
    // Returns the selected text.
    virtual base::string16 GetSelectedText() const = 0;

    // Returns true if |direction| should be enabled in the BiDi submenu.
    virtual bool IsTextDirectionEnabled(
        base::i18n::TextDirection direction) const = 0;

    // Returns true if |direction| should be checked in the BiDi submenu.
    virtual bool IsTextDirectionChecked(
        base::i18n::TextDirection direction) const = 0;

    // Updates the text direction to |direction|.
    virtual void UpdateTextDirection(base::i18n::TextDirection direction) = 0;
  };

  explicit TextServicesContextMenu(Delegate* delegate);

  // Methods for speaking.
  static void SpeakText(const base::string16& text);
  static void StopSpeaking();
  static bool IsSpeaking();

  // Appends text service items to |model|. A submenu is added for speech,
  // which |this| serves as the delegate for.
  void AppendToContextMenu(SimpleMenuModel* model);

  // Appends items to the context menu applicable to editable content. A
  // submenu is added for bidirection, which |this| serves as a delegate for.
  void AppendEditableItems(SimpleMenuModel* model);

  // SimpleMenuModel::Delegate:
  bool IsCommandIdChecked(int command_id) const override;
  bool IsCommandIdEnabled(int command_id) const override;
  void ExecuteCommand(int command_id, int event_flags) override;

 private:
  // Model for the "Speech" submenu.
  ui::SimpleMenuModel speech_submenu_model_;

  // Model for the BiDi input submenu.
  ui::SimpleMenuModel bidi_submenu_model_;

  Delegate* delegate_;  // Weak.

  DISALLOW_COPY_AND_ASSIGN(TextServicesContextMenu);
};

}  // namespace ui

#endif  // UI_BASE_COCOA_TEXT_SERVICES_CONTEXT_MENU_H_