summaryrefslogtreecommitdiffstats
path: root/webkit/glue/context_menu.h
blob: 620338aa3d7e2007bb54ee673e5af4219f087344 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Copyright (c) 2006-2009 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 WEBKIT_GLUE_CONTEXT_NODE_TYPES_H__
#define WEBKIT_GLUE_CONTEXT_NODE_TYPES_H__

#include <vector>

#include "base/basictypes.h"
#include "googleurl/src/gurl.h"

// The type of node that the user may perform a contextual action on
// in the WebView.
struct ContextNodeType {
  enum TypeBit {
    // No node is selected
    NONE = 0x0,

    // The top page is selected
    PAGE = 0x1,

    // A subframe page is selected
    FRAME = 0x2,

    // A link is selected
    LINK = 0x4,

    // An image is selected
    IMAGE = 0x8,

    // There is a textual or mixed selection that is selected
    SELECTION = 0x10,

    // An editable element is selected
    EDITABLE = 0x20,

    // A misspelled word is selected
    MISSPELLED_WORD = 0x40,

    // A video node is selected
    VIDEO = 0x80,

    // A video node is selected
    AUDIO = 0x100,
  };

  enum Capability {
    CAN_DO_NONE = 0x0,
    CAN_UNDO = 0x1,
    CAN_REDO = 0x2,
    CAN_CUT = 0x4,
    CAN_COPY = 0x8,
    CAN_PASTE = 0x10,
    CAN_DELETE = 0x20,
    CAN_SELECT_ALL = 0x40,
  };

  int32 type;
  ContextNodeType() : type(NONE) {}
  explicit ContextNodeType(int32 t) : type(t) {}
};

// Parameters structure used in ContextMenuParams with attributes needed to
// render the context menu for media elements.
//
// TODO(ajwong): Add support for multiple audio tracks and subtitles.
struct ContextMenuMediaParams {
  // Values for the bitfield representing the state of the media player.
  // If the state is IN_ERROR, most media controls should disable
  // themselves.
  enum PlayerStateBit {
    NO_STATE = 0x0,
    IN_ERROR = 0x1,
    PAUSED = 0x2,
    MUTED = 0x4,
    LOOP = 0x8,
    CAN_SAVE = 0x10,
  };

  // A bitfield representing the current state of the player, such as
  // playing, muted, etc.
  int32 player_state;

  // The current playback rate for this media element.
  double playback_rate;

  ContextMenuMediaParams()
      : player_state(NO_STATE), playback_rate(1.0f) {
  }
};

// Parameters structure for ViewHostMsg_ContextMenu.
// FIXME(beng): This would be more useful in the future and more efficient
//              if the parameters here weren't so literally mapped to what
//              they contain for the ContextMenu task. It might be better
//              to make the string fields more generic so that this object
//              could be used for more contextual actions.
struct ContextMenuParams {
  // This is the type of Context Node that the context menu was invoked on.
  ContextNodeType node_type;

  // These values represent the coordinates of the mouse when the context menu
  // was invoked.  Coords are relative to the associated RenderView's origin.
  int x;
  int y;

  // This is the URL of the link that encloses the node the context menu was
  // invoked on.
  GURL link_url;

  // The link URL to be used ONLY for "copy link address". We don't validate
  // this field in the frontend process.
  GURL unfiltered_link_url;

  // This is the source URL for the element that the context menu was
  // invoked on.  Example of elements with source URLs are img, audio, and
  // video.
  GURL src_url;

  // This is the URL of the top level page that the context menu was invoked
  // on.
  GURL page_url;

  // This is the URL of the subframe that the context menu was invoked on.
  GURL frame_url;

  // These are the parameters for the media element that the context menu
  // was invoked on.
  ContextMenuMediaParams media_params;

  // This is the text of the selection that the context menu was invoked on.
  std::wstring selection_text;

  // The misspelled word under the cursor, if any. Used to generate the
  // |dictionary_suggestions| list.
  std::wstring misspelled_word;

  // Suggested replacements for a misspelled word under the cursor.
  // This vector gets populated in the render process host
  // by intercepting ViewHostMsg_ContextMenu in ResourceMessageFilter
  // and populating dictionary_suggestions if the type is EDITABLE
  // and the misspelled_word is not empty.
  std::vector<std::wstring> dictionary_suggestions;

  // If editable, flag for whether spell check is enabled or not.
  bool spellcheck_enabled;

  // These flags indicate to the browser whether the renderer believes it is
  // able to perform the corresponding action.
  int edit_flags;

  // The security info for the resource we are showing the menu on.
  std::string security_info;

  // The character encoding of the frame on which the menu is invoked.
  std::string frame_charset;
};

struct MediaPlayerAction {
  enum CommandTypeBit {
    NONE = 0x0,
    PLAY = 0x1,
    PAUSE = 0x2,
    MUTE = 0x4,
    UNMUTE = 0x8,
    LOOP = 0x10,
    NO_LOOP = 0x20,
    SET_PLAYBACK_RATE = 0x40,
  };

  // A bitfield representing the actions that the context menu should execute
  // on the originating node.
  int32 command;

  // The new playback rate to set if the action is SET_PLAYBACK_RATE.
  double playback_rate;

  MediaPlayerAction() : command(NONE), playback_rate(1.0f) {}
  explicit MediaPlayerAction(int c) : command(c), playback_rate(1.0f) {}
  MediaPlayerAction(int c, double rate) : command(c), playback_rate(rate) {}
};

#endif  // WEBKIT_GLUE_CONTEXT_NODE_TYPES_H__