Merge lp:~chrisccoulson/oxide/refactor-webview-rwhv-interation into lp:~oxide-developers/oxide/oxide.trunk
- refactor-webview-rwhv-interation
- Merge into oxide.trunk
Status: | Merged |
---|---|
Merged at revision: | 1227 |
Proposed branch: | lp:~chrisccoulson/oxide/refactor-webview-rwhv-interation |
Merge into: | lp:~oxide-developers/oxide/oxide.trunk |
Diff against target: |
3849 lines (+1746/-856) 30 files modified
qt/core/browser/input/oxide_qt_input_method_context.cc (+424/-0) qt/core/browser/input/oxide_qt_input_method_context.h (+82/-0) qt/core/browser/input/oxide_qt_input_method_context_client.h (+36/-0) qt/core/browser/oxide_qt_web_view.cc (+16/-278) qt/core/browser/oxide_qt_web_view.h (+10/-19) qt/core/core.gyp (+6/-3) shared/browser/compositor/oxide_compositor.cc (+16/-30) shared/browser/compositor/oxide_compositor.h (+7/-27) shared/browser/compositor/oxide_compositor_client.h (+0/-2) shared/browser/compositor/oxide_compositor_observer.cc (+60/-0) shared/browser/compositor/oxide_compositor_observer.h (+49/-0) shared/browser/input/oxide_ime_bridge.cc (+31/-0) shared/browser/input/oxide_ime_bridge.h (+84/-0) shared/browser/input/oxide_ime_bridge_impl.cc (+157/-0) shared/browser/input/oxide_ime_bridge_impl.h (+69/-0) shared/browser/input/oxide_input_method_context.cc (+69/-0) shared/browser/input/oxide_input_method_context.h (+69/-0) shared/browser/input/oxide_input_method_context_observer.cc (+61/-0) shared/browser/input/oxide_input_method_context_observer.h (+49/-0) shared/browser/oxide_render_widget_host_view.cc (+120/-132) shared/browser/oxide_render_widget_host_view.h (+18/-16) shared/browser/oxide_render_widget_host_view_container.h (+35/-28) shared/browser/oxide_web_contents_view.cc (+45/-28) shared/browser/oxide_web_contents_view.h (+6/-2) shared/browser/oxide_web_view.cc (+139/-204) shared/browser/oxide_web_view.h (+30/-56) shared/browser/oxide_web_view_client.cc (+3/-13) shared/browser/oxide_web_view_client.h (+2/-17) shared/common/oxide_unowned_user_data.h (+41/-0) shared/shared.gyp (+12/-1) |
To merge this branch: | bzr merge lp:~chrisccoulson/oxide/refactor-webview-rwhv-interation |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Coulson | Pending | ||
Review via email: mp+274723@code.launchpad.net |
Commit message
Description of the change
- 1222. By Chris Coulson
-
Merge from trunk
- 1223. By Chris Coulson
-
When a RWHV is hidden, make sure we hide its cc::Layer
- 1224. By Chris Coulson
-
Don't proxy EvictCurrentFrame up to the WebView. This already doesn't make sense, and we should have a separate algorithm for LayerTreeHost eviction when a WebView is hidden. The current implementation won't make sense when we have Interstitial views anyway
- 1225. By Chris Coulson
-
Create RWHVs with a container
- 1226. By Chris Coulson
-
Change the behaviour of RWHV::IsShowing, and make sure that when we create a new cc::Layer it has the correct visibility
- 1227. By Chris Coulson
-
Fix RWHV::HasFocus
- 1228. By Chris Coulson
-
Merge from trunk
- 1229. By Chris Coulson
-
Merge from trunk
- 1230. By Chris Coulson
-
Split IME related calls from WebViewClient in to new classes
- 1231. By Chris Coulson
-
Attach the IM context when creating a new webview
- 1232. By Chris Coulson
-
Remove an unused method from WebViewClient
- 1233. By Chris Coulson
-
Fix cursor updates to work with interstitial views
- 1234. By Chris Coulson
-
Fix a shutdown crash
- 1235. By Chris Coulson
-
Turn a couple of CHECKs in to DCHECKs
- 1236. By Chris Coulson
-
Actually observe the input method context
- 1237. By Chris Coulson
-
Add CompositorObserver and make RWHV use this, rather than relying on WebView to proxy DidCommit to it
- 1238. By Chris Coulson
-
Fix a -Wreorder warning
- 1239. By Chris Coulson
-
Don't call Show() or Hide() when setting the container
- 1240. By Chris Coulson
-
We only need to set the RWHV visibility / focus for the first view
Preview Diff
1 | === added directory 'qt/core/browser/input' | |||
2 | === added file 'qt/core/browser/input/oxide_qt_input_method_context.cc' | |||
3 | --- qt/core/browser/input/oxide_qt_input_method_context.cc 1970-01-01 00:00:00 +0000 | |||
4 | +++ qt/core/browser/input/oxide_qt_input_method_context.cc 2015-10-21 17:31:00 +0000 | |||
5 | @@ -0,0 +1,424 @@ | |||
6 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
7 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
8 | 3 | |||
9 | 4 | // This library is free software; you can redistribute it and/or | ||
10 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
11 | 6 | // License as published by the Free Software Foundation; either | ||
12 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
13 | 8 | |||
14 | 9 | // This library is distributed in the hope that it will be useful, | ||
15 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | 12 | // Lesser General Public License for more details. | ||
18 | 13 | |||
19 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
20 | 15 | // License along with this library; if not, write to the Free Software | ||
21 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | 17 | |||
23 | 18 | #include "oxide_qt_input_method_context.h" | ||
24 | 19 | |||
25 | 20 | #include <string> | ||
26 | 21 | #include <vector> | ||
27 | 22 | |||
28 | 23 | #include <QFocusEvent> | ||
29 | 24 | #include <QGuiApplication> | ||
30 | 25 | #include <QInputMethod> | ||
31 | 26 | #include <QInputMethodEvent> | ||
32 | 27 | #include <QRect> | ||
33 | 28 | #include <QString> | ||
34 | 29 | #include <QTextCharFormat> | ||
35 | 30 | #include <QWindow> | ||
36 | 31 | |||
37 | 32 | #include "base/strings/utf_string_conversions.h" | ||
38 | 33 | #include "third_party/skia/include/core/SkColor.h" | ||
39 | 34 | #include "third_party/WebKit/public/platform/WebColor.h" | ||
40 | 35 | #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | ||
41 | 36 | #include "ui/base/ime/text_input_type.h" | ||
42 | 37 | #include "ui/gfx/geometry/rect.h" | ||
43 | 38 | #include "ui/gfx/range/range.h" | ||
44 | 39 | |||
45 | 40 | #include "shared/browser/input/oxide_ime_bridge.h" | ||
46 | 41 | |||
47 | 42 | #include "oxide_qt_input_method_context_client.h" | ||
48 | 43 | |||
49 | 44 | namespace oxide { | ||
50 | 45 | namespace qt { | ||
51 | 46 | |||
52 | 47 | namespace { | ||
53 | 48 | |||
54 | 49 | Qt::InputMethodHints QImHintsFromInputType(ui::TextInputType type) { | ||
55 | 50 | switch (type) { | ||
56 | 51 | case ui::TEXT_INPUT_TYPE_TEXT: | ||
57 | 52 | case ui::TEXT_INPUT_TYPE_TEXT_AREA: | ||
58 | 53 | case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE: | ||
59 | 54 | return Qt::ImhPreferLowercase; | ||
60 | 55 | case ui::TEXT_INPUT_TYPE_PASSWORD: | ||
61 | 56 | return Qt::ImhHiddenText | Qt::ImhSensitiveData | | ||
62 | 57 | Qt::ImhNoAutoUppercase | Qt::ImhPreferLowercase | | ||
63 | 58 | Qt::ImhNoPredictiveText; | ||
64 | 59 | case ui::TEXT_INPUT_TYPE_SEARCH: | ||
65 | 60 | return Qt::ImhNoAutoUppercase | Qt::ImhPreferLowercase; | ||
66 | 61 | case ui::TEXT_INPUT_TYPE_EMAIL: | ||
67 | 62 | return Qt::ImhEmailCharactersOnly; | ||
68 | 63 | case ui::TEXT_INPUT_TYPE_NUMBER: | ||
69 | 64 | return Qt::ImhFormattedNumbersOnly; | ||
70 | 65 | case ui::TEXT_INPUT_TYPE_TELEPHONE: | ||
71 | 66 | return Qt::ImhDialableCharactersOnly; | ||
72 | 67 | case ui::TEXT_INPUT_TYPE_URL: | ||
73 | 68 | return Qt::ImhUrlCharactersOnly; | ||
74 | 69 | case ui::TEXT_INPUT_TYPE_DATE: | ||
75 | 70 | case ui::TEXT_INPUT_TYPE_MONTH: | ||
76 | 71 | case ui::TEXT_INPUT_TYPE_WEEK: | ||
77 | 72 | return Qt::ImhDate; | ||
78 | 73 | case ui::TEXT_INPUT_TYPE_DATE_TIME: | ||
79 | 74 | case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL: | ||
80 | 75 | case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD: | ||
81 | 76 | return Qt::ImhDate | Qt::ImhTime; | ||
82 | 77 | case ui::TEXT_INPUT_TYPE_TIME: | ||
83 | 78 | return Qt::ImhTime; | ||
84 | 79 | default: | ||
85 | 80 | return Qt::ImhNone; | ||
86 | 81 | } | ||
87 | 82 | } | ||
88 | 83 | |||
89 | 84 | } | ||
90 | 85 | |||
91 | 86 | void InputMethodContext::OnInputPanelVisibilityChanged() { | ||
92 | 87 | } | ||
93 | 88 | |||
94 | 89 | bool InputMethodContext::ShouldShowInputPanel() const { | ||
95 | 90 | if (!ime_bridge()) { | ||
96 | 91 | return false; | ||
97 | 92 | } | ||
98 | 93 | |||
99 | 94 | if (ime_bridge()->text_input_type() != ui::TEXT_INPUT_TYPE_NONE && | ||
100 | 95 | ime_bridge()->show_ime_if_needed() && | ||
101 | 96 | ime_bridge()->focused_node_is_editable()) { | ||
102 | 97 | return true; | ||
103 | 98 | } | ||
104 | 99 | |||
105 | 100 | return false; | ||
106 | 101 | } | ||
107 | 102 | |||
108 | 103 | bool InputMethodContext::ShouldHideInputPanel() const { | ||
109 | 104 | if (!ime_bridge()) { | ||
110 | 105 | return true; | ||
111 | 106 | } | ||
112 | 107 | |||
113 | 108 | if (ime_bridge()->text_input_type() == ui::TEXT_INPUT_TYPE_NONE && | ||
114 | 109 | !ime_bridge()->focused_node_is_editable()) { | ||
115 | 110 | return true; | ||
116 | 111 | } | ||
117 | 112 | |||
118 | 113 | return false; | ||
119 | 114 | } | ||
120 | 115 | |||
121 | 116 | void InputMethodContext::SetInputPanelVisibility(bool visible) { | ||
122 | 117 | client_->SetInputMethodEnabled(visible); | ||
123 | 118 | |||
124 | 119 | if (!visible) { | ||
125 | 120 | has_input_method_state_ = false; | ||
126 | 121 | } | ||
127 | 122 | |||
128 | 123 | // Do not check whether the input method is currently visible here, to avoid | ||
129 | 124 | // a possible race condition: if hide() and show() are called very quickly | ||
130 | 125 | // in a row, when show() is called the hide() request might not have | ||
131 | 126 | // completed yet, and isVisible() could return true. | ||
132 | 127 | // See https://launchpad.net/bugs/1377755 | ||
133 | 128 | QInputMethod* im = QGuiApplication::inputMethod(); | ||
134 | 129 | if (im) { | ||
135 | 130 | im->setVisible(visible); | ||
136 | 131 | } | ||
137 | 132 | } | ||
138 | 133 | |||
139 | 134 | bool InputMethodContext::IsInputPanelVisible() const { | ||
140 | 135 | QInputMethod* im = QGuiApplication::inputMethod(); | ||
141 | 136 | if (!im) { | ||
142 | 137 | return false; | ||
143 | 138 | } | ||
144 | 139 | |||
145 | 140 | return im->isVisible(); | ||
146 | 141 | } | ||
147 | 142 | |||
148 | 143 | void InputMethodContext::TextInputStateChanged() { | ||
149 | 144 | if (!client_) { | ||
150 | 145 | return; | ||
151 | 146 | } | ||
152 | 147 | |||
153 | 148 | if (!client_->HasFocus()) { | ||
154 | 149 | return; | ||
155 | 150 | } | ||
156 | 151 | |||
157 | 152 | // Don't notify if type is none. See https://launchpad.net/bugs/1381083 | ||
158 | 153 | if (ime_bridge() && | ||
159 | 154 | ime_bridge()->text_input_type() != ui::TEXT_INPUT_TYPE_NONE) { | ||
160 | 155 | QGuiApplication::inputMethod()->update( | ||
161 | 156 | static_cast<Qt::InputMethodQueries>(Qt::ImQueryInput | Qt::ImHints)); | ||
162 | 157 | } | ||
163 | 158 | |||
164 | 159 | if (ShouldShowInputPanel()) { | ||
165 | 160 | SetInputPanelVisibility(true); | ||
166 | 161 | } else if (ShouldHideInputPanel()) { | ||
167 | 162 | SetInputPanelVisibility(false); | ||
168 | 163 | } | ||
169 | 164 | } | ||
170 | 165 | |||
171 | 166 | void InputMethodContext::SelectionBoundsChanged() { | ||
172 | 167 | if (!client_) { | ||
173 | 168 | return; | ||
174 | 169 | } | ||
175 | 170 | |||
176 | 171 | if (!client_->HasFocus()) { | ||
177 | 172 | return; | ||
178 | 173 | } | ||
179 | 174 | |||
180 | 175 | QInputMethod* im = QGuiApplication::inputMethod(); | ||
181 | 176 | if (!im) { | ||
182 | 177 | return; | ||
183 | 178 | } | ||
184 | 179 | |||
185 | 180 | im->update(static_cast<Qt::InputMethodQueries>( | ||
186 | 181 | Qt::ImCursorRectangle | ||
187 | 182 | | Qt::ImCursorPosition | ||
188 | 183 | | Qt::ImAnchorPosition | ||
189 | 184 | #if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) | ||
190 | 185 | | Qt::ImTextBeforeCursor | ||
191 | 186 | | Qt::ImTextAfterCursor | ||
192 | 187 | #endif | ||
193 | 188 | )); | ||
194 | 189 | } | ||
195 | 190 | |||
196 | 191 | void InputMethodContext::SelectionChanged() { | ||
197 | 192 | if (!client_) { | ||
198 | 193 | return; | ||
199 | 194 | } | ||
200 | 195 | |||
201 | 196 | if (!client_->HasFocus()) { | ||
202 | 197 | return; | ||
203 | 198 | } | ||
204 | 199 | |||
205 | 200 | QInputMethod* im = QGuiApplication::inputMethod(); | ||
206 | 201 | if (!im) { | ||
207 | 202 | return; | ||
208 | 203 | } | ||
209 | 204 | |||
210 | 205 | im->update(static_cast<Qt::InputMethodQueries>( | ||
211 | 206 | Qt::ImSurroundingText | ||
212 | 207 | | Qt::ImCurrentSelection | ||
213 | 208 | #if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) | ||
214 | 209 | | Qt::ImTextBeforeCursor | ||
215 | 210 | | Qt::ImTextAfterCursor | ||
216 | 211 | #endif | ||
217 | 212 | )); | ||
218 | 213 | } | ||
219 | 214 | |||
220 | 215 | void InputMethodContext::CancelComposition() { | ||
221 | 216 | if (!has_input_method_state_) { | ||
222 | 217 | return; | ||
223 | 218 | } | ||
224 | 219 | |||
225 | 220 | QInputMethod* im = QGuiApplication::inputMethod(); | ||
226 | 221 | if (!im) { | ||
227 | 222 | return; | ||
228 | 223 | } | ||
229 | 224 | |||
230 | 225 | im->reset(); | ||
231 | 226 | } | ||
232 | 227 | |||
233 | 228 | void InputMethodContext::FocusedNodeChanged() { | ||
234 | 229 | if (!client_) { | ||
235 | 230 | return; | ||
236 | 231 | } | ||
237 | 232 | |||
238 | 233 | // Work around for https://launchpad.net/bugs/1323743 | ||
239 | 234 | if (QGuiApplication::focusWindow() && | ||
240 | 235 | QGuiApplication::focusWindow()->focusObject()) { | ||
241 | 236 | QGuiApplication::focusWindow()->focusObjectChanged( | ||
242 | 237 | QGuiApplication::focusWindow()->focusObject()); | ||
243 | 238 | } | ||
244 | 239 | |||
245 | 240 | if (ShouldHideInputPanel() && client_->HasFocus()) { | ||
246 | 241 | SetInputPanelVisibility(false); | ||
247 | 242 | } else if (!has_input_method_state_ && ShouldShowInputPanel()) { | ||
248 | 243 | // See https://launchpad.net/bugs/1400372 | ||
249 | 244 | SetInputPanelVisibility(true); | ||
250 | 245 | } else if (has_input_method_state_ && | ||
251 | 246 | ime_bridge() && | ||
252 | 247 | ime_bridge()->focused_node_is_editable() && | ||
253 | 248 | QGuiApplication::inputMethod()) { | ||
254 | 249 | QGuiApplication::inputMethod()->reset(); | ||
255 | 250 | } | ||
256 | 251 | } | ||
257 | 252 | |||
258 | 253 | InputMethodContext::InputMethodContext(InputMethodContextClient* client) | ||
259 | 254 | : client_(client), | ||
260 | 255 | has_input_method_state_(false) { | ||
261 | 256 | QInputMethod* im = QGuiApplication::inputMethod(); | ||
262 | 257 | if (im) { | ||
263 | 258 | connect(im, SIGNAL(visibleChanged()), | ||
264 | 259 | SLOT(OnInputPanelVisibilityChanged())); | ||
265 | 260 | } | ||
266 | 261 | } | ||
267 | 262 | |||
268 | 263 | InputMethodContext::~InputMethodContext() { | ||
269 | 264 | QInputMethod* im = QGuiApplication::inputMethod(); | ||
270 | 265 | if (im) { | ||
271 | 266 | im->disconnect(this); | ||
272 | 267 | } | ||
273 | 268 | } | ||
274 | 269 | |||
275 | 270 | void InputMethodContext::DetachClient() { | ||
276 | 271 | client_ = nullptr; | ||
277 | 272 | } | ||
278 | 273 | |||
279 | 274 | QVariant InputMethodContext::Query(Qt::InputMethodQuery query) const { | ||
280 | 275 | switch (query) { | ||
281 | 276 | case Qt::ImHints: | ||
282 | 277 | if (!ime_bridge()) { | ||
283 | 278 | return QVariant(QImHintsFromInputType(ui::TEXT_INPUT_TYPE_NONE)); | ||
284 | 279 | } | ||
285 | 280 | return QVariant(QImHintsFromInputType(ime_bridge()->text_input_type())); | ||
286 | 281 | case Qt::ImCursorRectangle: { | ||
287 | 282 | if (!ime_bridge()) { | ||
288 | 283 | return QRect(); | ||
289 | 284 | } | ||
290 | 285 | // XXX: Is this in the right coordinate space? | ||
291 | 286 | return QRect(ime_bridge()->caret_rect().x(), | ||
292 | 287 | ime_bridge()->caret_rect().y(), | ||
293 | 288 | ime_bridge()->caret_rect().width(), | ||
294 | 289 | ime_bridge()->caret_rect().height()); | ||
295 | 290 | } | ||
296 | 291 | case Qt::ImCursorPosition: | ||
297 | 292 | if (!ime_bridge()) { | ||
298 | 293 | return 0; | ||
299 | 294 | } | ||
300 | 295 | return static_cast<int>(ime_bridge()->selection_cursor_position() & | ||
301 | 296 | INT_MAX); | ||
302 | 297 | case Qt::ImSurroundingText: | ||
303 | 298 | if (!ime_bridge()) { | ||
304 | 299 | return QString(); | ||
305 | 300 | } | ||
306 | 301 | return QString::fromStdString( | ||
307 | 302 | base::UTF16ToUTF8(ime_bridge()->GetSelectionText())); | ||
308 | 303 | case Qt::ImCurrentSelection: | ||
309 | 304 | if (!ime_bridge()) { | ||
310 | 305 | return QString(); | ||
311 | 306 | } | ||
312 | 307 | return QString::fromStdString( | ||
313 | 308 | base::UTF16ToUTF8(ime_bridge()->GetSelectedText())); | ||
314 | 309 | case Qt::ImAnchorPosition: | ||
315 | 310 | if (!ime_bridge()) { | ||
316 | 311 | return 0; | ||
317 | 312 | } | ||
318 | 313 | return static_cast<int>(ime_bridge()->selection_anchor_position() & | ||
319 | 314 | INT_MAX); | ||
320 | 315 | #if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) | ||
321 | 316 | case Qt::ImTextBeforeCursor: { | ||
322 | 317 | if (!ime_bridge()) { | ||
323 | 318 | return QString(); | ||
324 | 319 | } | ||
325 | 320 | std::string text = base::UTF16ToUTF8(ime_bridge()->GetSelectionText()); | ||
326 | 321 | return QString::fromStdString( | ||
327 | 322 | text.substr(0, ime_bridge()->selection_cursor_position())); | ||
328 | 323 | } | ||
329 | 324 | case Qt::ImTextAfterCursor: { | ||
330 | 325 | if (!ime_bridge()) { | ||
331 | 326 | return QString(); | ||
332 | 327 | } | ||
333 | 328 | std::string text = base::UTF16ToUTF8(ime_bridge()->GetSelectionText()); | ||
334 | 329 | if (ime_bridge()->selection_cursor_position() > text.length()) { | ||
335 | 330 | return QString(); | ||
336 | 331 | } | ||
337 | 332 | return QString::fromStdString( | ||
338 | 333 | text.substr(ime_bridge()->selection_cursor_position(), | ||
339 | 334 | std::string::npos)); | ||
340 | 335 | } | ||
341 | 336 | #endif | ||
342 | 337 | default: | ||
343 | 338 | break; | ||
344 | 339 | } | ||
345 | 340 | |||
346 | 341 | return QVariant(); | ||
347 | 342 | } | ||
348 | 343 | |||
349 | 344 | void InputMethodContext::FocusChanged(QFocusEvent* event) { | ||
350 | 345 | if (!event->gotFocus()) { | ||
351 | 346 | return; | ||
352 | 347 | } | ||
353 | 348 | |||
354 | 349 | if (!ShouldShowInputPanel()) { | ||
355 | 350 | return; | ||
356 | 351 | } | ||
357 | 352 | |||
358 | 353 | SetInputPanelVisibility(true); | ||
359 | 354 | } | ||
360 | 355 | |||
361 | 356 | void InputMethodContext::HandleEvent(QInputMethodEvent* event) { | ||
362 | 357 | QString commit_string = event->commitString(); | ||
363 | 358 | |||
364 | 359 | if (!commit_string.isEmpty()) { | ||
365 | 360 | gfx::Range replacement_range = gfx::Range::InvalidRange(); | ||
366 | 361 | if (event->replacementLength() > 0) { | ||
367 | 362 | replacement_range.set_start(event->replacementStart()); | ||
368 | 363 | replacement_range.set_end(event->replacementStart() + | ||
369 | 364 | event->replacementLength()); | ||
370 | 365 | } | ||
371 | 366 | if (ime_bridge()) { | ||
372 | 367 | ime_bridge()->CommitText(base::UTF8ToUTF16(commit_string.toStdString()), | ||
373 | 368 | replacement_range); | ||
374 | 369 | } | ||
375 | 370 | } | ||
376 | 371 | |||
377 | 372 | QString preedit_string = event->preeditString(); | ||
378 | 373 | |||
379 | 374 | std::vector<blink::WebCompositionUnderline> underlines; | ||
380 | 375 | int cursor_position = -1; | ||
381 | 376 | gfx::Range selection_range = gfx::Range::InvalidRange(); | ||
382 | 377 | |||
383 | 378 | for (const auto& attribute : event->attributes()) { | ||
384 | 379 | switch (attribute.type) { | ||
385 | 380 | case QInputMethodEvent::Cursor: | ||
386 | 381 | if (attribute.length > 0) { | ||
387 | 382 | cursor_position = attribute.start; | ||
388 | 383 | } | ||
389 | 384 | break; | ||
390 | 385 | case QInputMethodEvent::Selection: | ||
391 | 386 | selection_range.set_start( | ||
392 | 387 | qMin(attribute.start, (attribute.start + attribute.length))); | ||
393 | 388 | selection_range.set_end( | ||
394 | 389 | qMax(attribute.start, (attribute.start + attribute.length))); | ||
395 | 390 | break; | ||
396 | 391 | case QInputMethodEvent::TextFormat: { | ||
397 | 392 | QTextCharFormat format = | ||
398 | 393 | attribute.value.value<QTextFormat>().toCharFormat(); | ||
399 | 394 | blink::WebColor color = format.underlineColor().rgba(); | ||
400 | 395 | int start = qMin(attribute.start, (attribute.start + attribute.length)); | ||
401 | 396 | int end = qMax(attribute.start, (attribute.start + attribute.length)); | ||
402 | 397 | blink::WebCompositionUnderline underline( | ||
403 | 398 | start, end, color, false, SK_ColorTRANSPARENT); | ||
404 | 399 | underlines.push_back(underline); | ||
405 | 400 | break; | ||
406 | 401 | } | ||
407 | 402 | default: | ||
408 | 403 | break; | ||
409 | 404 | } | ||
410 | 405 | } | ||
411 | 406 | |||
412 | 407 | if (!selection_range.IsValid()) { | ||
413 | 408 | selection_range = | ||
414 | 409 | gfx::Range(cursor_position > 0 ? | ||
415 | 410 | cursor_position : | ||
416 | 411 | preedit_string.length()); | ||
417 | 412 | } | ||
418 | 413 | |||
419 | 414 | if (ime_bridge()) { | ||
420 | 415 | ime_bridge()->SetComposingText( | ||
421 | 416 | base::UTF8ToUTF16(preedit_string.toStdString()), | ||
422 | 417 | underlines, selection_range); | ||
423 | 418 | } | ||
424 | 419 | |||
425 | 420 | has_input_method_state_ = !preedit_string.isEmpty(); | ||
426 | 421 | } | ||
427 | 422 | |||
428 | 423 | } // namespace qt | ||
429 | 424 | } // namespace oxide | ||
430 | 0 | 425 | ||
431 | === added file 'qt/core/browser/input/oxide_qt_input_method_context.h' | |||
432 | --- qt/core/browser/input/oxide_qt_input_method_context.h 1970-01-01 00:00:00 +0000 | |||
433 | +++ qt/core/browser/input/oxide_qt_input_method_context.h 2015-10-21 17:31:00 +0000 | |||
434 | @@ -0,0 +1,82 @@ | |||
435 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
436 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
437 | 3 | |||
438 | 4 | // This library is free software; you can redistribute it and/or | ||
439 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
440 | 6 | // License as published by the Free Software Foundation; either | ||
441 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
442 | 8 | |||
443 | 9 | // This library is distributed in the hope that it will be useful, | ||
444 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
445 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
446 | 12 | // Lesser General Public License for more details. | ||
447 | 13 | |||
448 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
449 | 15 | // License along with this library; if not, write to the Free Software | ||
450 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
451 | 17 | |||
452 | 18 | #ifndef _OXIDE_QT_CORE_BROWSER_INPUT_INPUT_METHOD_CONTEXT_H_ | ||
453 | 19 | #define _OXIDE_QT_CORE_BROWSER_INPUT_INPUT_METHOD_CONTEXT_H_ | ||
454 | 20 | |||
455 | 21 | #include <QObject> | ||
456 | 22 | #include <QtGlobal> | ||
457 | 23 | #include <QVariant> | ||
458 | 24 | |||
459 | 25 | #include "base/macros.h" | ||
460 | 26 | |||
461 | 27 | #include "shared/browser/input/oxide_input_method_context.h" | ||
462 | 28 | |||
463 | 29 | QT_BEGIN_NAMESPACE | ||
464 | 30 | class QFocusEvent; | ||
465 | 31 | class QInputMethodEvent; | ||
466 | 32 | QT_END_NAMESPACE | ||
467 | 33 | |||
468 | 34 | namespace oxide { | ||
469 | 35 | namespace qt { | ||
470 | 36 | |||
471 | 37 | class InputMethodContextClient; | ||
472 | 38 | |||
473 | 39 | class InputMethodContext : public QObject, | ||
474 | 40 | public oxide::InputMethodContext { | ||
475 | 41 | Q_OBJECT | ||
476 | 42 | |||
477 | 43 | public: | ||
478 | 44 | InputMethodContext(InputMethodContextClient* client); | ||
479 | 45 | ~InputMethodContext() override; | ||
480 | 46 | |||
481 | 47 | QVariant Query(Qt::InputMethodQuery query) const; | ||
482 | 48 | |||
483 | 49 | // Null out |client_| to prevent calls back in to it during its destructor | ||
484 | 50 | void DetachClient(); | ||
485 | 51 | |||
486 | 52 | void FocusChanged(QFocusEvent* event); | ||
487 | 53 | void HandleEvent(QInputMethodEvent* event); | ||
488 | 54 | |||
489 | 55 | private Q_SLOTS: | ||
490 | 56 | void OnInputPanelVisibilityChanged(); | ||
491 | 57 | |||
492 | 58 | private: | ||
493 | 59 | bool ShouldShowInputPanel() const; | ||
494 | 60 | bool ShouldHideInputPanel() const; | ||
495 | 61 | |||
496 | 62 | void SetInputPanelVisibility(bool visible); | ||
497 | 63 | |||
498 | 64 | // oxide::InputMethodContext implementation | ||
499 | 65 | bool IsInputPanelVisible() const override; | ||
500 | 66 | void TextInputStateChanged() override; | ||
501 | 67 | void SelectionBoundsChanged() override; | ||
502 | 68 | void SelectionChanged() override; | ||
503 | 69 | void CancelComposition() override; | ||
504 | 70 | void FocusedNodeChanged() override; | ||
505 | 71 | |||
506 | 72 | InputMethodContextClient* client_; // Owns us | ||
507 | 73 | |||
508 | 74 | bool has_input_method_state_; | ||
509 | 75 | |||
510 | 76 | DISALLOW_COPY_AND_ASSIGN(InputMethodContext); | ||
511 | 77 | }; | ||
512 | 78 | |||
513 | 79 | } // namespace qt | ||
514 | 80 | } // namespace oxide | ||
515 | 81 | |||
516 | 82 | #endif // _OXIDE_QT_CORE_BROWSER_INPUT_INPUT_METHOD_CONTEXT_H_ | ||
517 | 0 | 83 | ||
518 | === added file 'qt/core/browser/input/oxide_qt_input_method_context_client.h' | |||
519 | --- qt/core/browser/input/oxide_qt_input_method_context_client.h 1970-01-01 00:00:00 +0000 | |||
520 | +++ qt/core/browser/input/oxide_qt_input_method_context_client.h 2015-10-21 17:31:00 +0000 | |||
521 | @@ -0,0 +1,36 @@ | |||
522 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
523 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
524 | 3 | |||
525 | 4 | // This library is free software; you can redistribute it and/or | ||
526 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
527 | 6 | // License as published by the Free Software Foundation; either | ||
528 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
529 | 8 | |||
530 | 9 | // This library is distributed in the hope that it will be useful, | ||
531 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
532 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
533 | 12 | // Lesser General Public License for more details. | ||
534 | 13 | |||
535 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
536 | 15 | // License along with this library; if not, write to the Free Software | ||
537 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
538 | 17 | |||
539 | 18 | #ifndef _OXIDE_QT_CORE_BROWSER_INPUT_INPUT_METHOD_CONTEXT_CLIENT_H_ | ||
540 | 19 | #define _OXIDE_QT_CORE_BROWSER_INPUT_INPUT_METHOD_CONTEXT_CLIENT_H_ | ||
541 | 20 | |||
542 | 21 | namespace oxide { | ||
543 | 22 | namespace qt { | ||
544 | 23 | |||
545 | 24 | class InputMethodContextClient { | ||
546 | 25 | public: | ||
547 | 26 | virtual ~InputMethodContextClient() {} | ||
548 | 27 | |||
549 | 28 | virtual bool HasFocus() const = 0; | ||
550 | 29 | |||
551 | 30 | virtual void SetInputMethodEnabled(bool enabled) = 0; | ||
552 | 31 | }; | ||
553 | 32 | |||
554 | 33 | } // namespace qt | ||
555 | 34 | } // namespace oxide | ||
556 | 35 | |||
557 | 36 | #endif // _OXIDE_QT_CORE_BROWSER_INPUT_INPUT_METHOD_CONTEXT_CLIENT_H_ | ||
558 | 0 | 37 | ||
559 | === modified file 'qt/core/browser/oxide_qt_web_view.cc' | |||
560 | --- qt/core/browser/oxide_qt_web_view.cc 2015-10-16 21:36:30 +0000 | |||
561 | +++ qt/core/browser/oxide_qt_web_view.cc 2015-10-21 17:31:00 +0000 | |||
562 | @@ -25,14 +25,12 @@ | |||
563 | 25 | #include <QCursor> | 25 | #include <QCursor> |
564 | 26 | #include <QGuiApplication> | 26 | #include <QGuiApplication> |
565 | 27 | #include <QInputEvent> | 27 | #include <QInputEvent> |
566 | 28 | #include <QInputMethod> | ||
567 | 29 | #include <QKeyEvent> | 28 | #include <QKeyEvent> |
568 | 29 | #include <QPixmap> | ||
569 | 30 | #include <QScreen> | 30 | #include <QScreen> |
570 | 31 | #include <QString> | 31 | #include <QString> |
571 | 32 | #include <QtDebug> | 32 | #include <QtDebug> |
572 | 33 | #include <QTextCharFormat> | ||
573 | 34 | #include <QUrl> | 33 | #include <QUrl> |
574 | 35 | #include <QWindow> | ||
575 | 36 | 34 | ||
576 | 37 | #include "base/logging.h" | 35 | #include "base/logging.h" |
577 | 38 | #include "base/macros.h" | 36 | #include "base/macros.h" |
578 | @@ -46,16 +44,12 @@ | |||
579 | 46 | #include "content/public/browser/navigation_controller.h" | 44 | #include "content/public/browser/navigation_controller.h" |
580 | 47 | #include "content/browser/web_contents/web_contents_impl.h" | 45 | #include "content/browser/web_contents/web_contents_impl.h" |
581 | 48 | #include "net/base/net_errors.h" | 46 | #include "net/base/net_errors.h" |
582 | 49 | #include "third_party/skia/include/core/SkColor.h" | ||
583 | 50 | #include "third_party/WebKit/public/platform/WebColor.h" | ||
584 | 51 | #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 47 | #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
585 | 52 | #include "third_party/WebKit/public/platform/WebTopControlsState.h" | 48 | #include "third_party/WebKit/public/platform/WebTopControlsState.h" |
586 | 53 | #include "ui/base/ime/text_input_type.h" | ||
587 | 54 | #include "ui/events/event.h" | 49 | #include "ui/events/event.h" |
588 | 55 | #include "ui/gfx/geometry/point.h" | 50 | #include "ui/gfx/geometry/point.h" |
589 | 56 | #include "ui/gfx/geometry/rect.h" | 51 | #include "ui/gfx/geometry/rect.h" |
590 | 57 | #include "ui/gfx/geometry/size.h" | 52 | #include "ui/gfx/geometry/size.h" |
591 | 58 | #include "ui/gfx/range/range.h" | ||
592 | 59 | #include "url/gurl.h" | 53 | #include "url/gurl.h" |
593 | 60 | 54 | ||
594 | 61 | #include "qt/core/api/oxideqdownloadrequest.h" | 55 | #include "qt/core/api/oxideqdownloadrequest.h" |
595 | @@ -74,6 +68,7 @@ | |||
596 | 74 | #include "qt/core/api/oxideqfindcontroller_p.h" | 68 | #include "qt/core/api/oxideqfindcontroller_p.h" |
597 | 75 | #include "qt/core/api/oxideqwebpreferences.h" | 69 | #include "qt/core/api/oxideqwebpreferences.h" |
598 | 76 | #include "qt/core/api/oxideqwebpreferences_p.h" | 70 | #include "qt/core/api/oxideqwebpreferences_p.h" |
599 | 71 | #include "qt/core/browser/input/oxide_qt_input_method_context.h" | ||
600 | 77 | #include "qt/core/glue/oxide_qt_web_frame_proxy_client.h" | 72 | #include "qt/core/glue/oxide_qt_web_frame_proxy_client.h" |
601 | 78 | #include "qt/core/glue/oxide_qt_web_view_proxy_client.h" | 73 | #include "qt/core/glue/oxide_qt_web_view_proxy_client.h" |
602 | 79 | #include "shared/browser/compositor/oxide_compositor_frame_data.h" | 74 | #include "shared/browser/compositor/oxide_compositor_frame_data.h" |
603 | @@ -236,41 +231,6 @@ | |||
604 | 236 | return QCursor(cs); | 231 | return QCursor(cs); |
605 | 237 | } | 232 | } |
606 | 238 | 233 | ||
607 | 239 | Qt::InputMethodHints QImHintsFromInputType(ui::TextInputType type) { | ||
608 | 240 | switch (type) { | ||
609 | 241 | case ui::TEXT_INPUT_TYPE_TEXT: | ||
610 | 242 | case ui::TEXT_INPUT_TYPE_TEXT_AREA: | ||
611 | 243 | case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE: | ||
612 | 244 | return Qt::ImhPreferLowercase; | ||
613 | 245 | case ui::TEXT_INPUT_TYPE_PASSWORD: | ||
614 | 246 | return Qt::ImhHiddenText | Qt::ImhSensitiveData | | ||
615 | 247 | Qt::ImhNoAutoUppercase | Qt::ImhPreferLowercase | | ||
616 | 248 | Qt::ImhNoPredictiveText; | ||
617 | 249 | case ui::TEXT_INPUT_TYPE_SEARCH: | ||
618 | 250 | return Qt::ImhNoAutoUppercase | Qt::ImhPreferLowercase; | ||
619 | 251 | case ui::TEXT_INPUT_TYPE_EMAIL: | ||
620 | 252 | return Qt::ImhEmailCharactersOnly; | ||
621 | 253 | case ui::TEXT_INPUT_TYPE_NUMBER: | ||
622 | 254 | return Qt::ImhFormattedNumbersOnly; | ||
623 | 255 | case ui::TEXT_INPUT_TYPE_TELEPHONE: | ||
624 | 256 | return Qt::ImhDialableCharactersOnly; | ||
625 | 257 | case ui::TEXT_INPUT_TYPE_URL: | ||
626 | 258 | return Qt::ImhUrlCharactersOnly; | ||
627 | 259 | case ui::TEXT_INPUT_TYPE_DATE: | ||
628 | 260 | case ui::TEXT_INPUT_TYPE_MONTH: | ||
629 | 261 | case ui::TEXT_INPUT_TYPE_WEEK: | ||
630 | 262 | return Qt::ImhDate; | ||
631 | 263 | case ui::TEXT_INPUT_TYPE_DATE_TIME: | ||
632 | 264 | case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL: | ||
633 | 265 | case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD: | ||
634 | 266 | return Qt::ImhDate | Qt::ImhTime; | ||
635 | 267 | case ui::TEXT_INPUT_TYPE_TIME: | ||
636 | 268 | return Qt::ImhTime; | ||
637 | 269 | default: | ||
638 | 270 | return Qt::ImhNone; | ||
639 | 271 | } | ||
640 | 272 | } | ||
641 | 273 | |||
642 | 274 | static const char* STATE_SERIALIZER_MAGIC_NUMBER = "oxide"; | 234 | static const char* STATE_SERIALIZER_MAGIC_NUMBER = "oxide"; |
643 | 275 | static uint16_t STATE_SERIALIZER_VERSION = 1; | 235 | static uint16_t STATE_SERIALIZER_VERSION = 1; |
644 | 276 | 236 | ||
645 | @@ -429,22 +389,12 @@ | |||
646 | 429 | QRect rect_; | 389 | QRect rect_; |
647 | 430 | }; | 390 | }; |
648 | 431 | 391 | ||
649 | 432 | void WebView::OnInputPanelVisibilityChanged() { | ||
650 | 433 | view_->InputPanelVisibilityChanged(); | ||
651 | 434 | } | ||
652 | 435 | |||
653 | 436 | WebView::WebView(WebViewProxyClient* client, | 392 | WebView::WebView(WebViewProxyClient* client, |
654 | 437 | OxideQSecurityStatus* security_status) | 393 | OxideQSecurityStatus* security_status) |
657 | 438 | : client_(client), | 394 | : input_method_context_(new InputMethodContext(this)), |
658 | 439 | has_input_method_state_(false), | 395 | client_(client), |
659 | 440 | security_status_(security_status), | 396 | security_status_(security_status), |
667 | 441 | frame_tree_torn_down_(false) { | 397 | frame_tree_torn_down_(false) {} |
661 | 442 | QInputMethod* im = QGuiApplication::inputMethod(); | ||
662 | 443 | if (im) { | ||
663 | 444 | connect(im, SIGNAL(visibleChanged()), | ||
664 | 445 | SLOT(OnInputPanelVisibilityChanged())); | ||
665 | 446 | } | ||
666 | 447 | } | ||
668 | 448 | 398 | ||
669 | 449 | float WebView::GetDeviceScaleFactor() const { | 399 | float WebView::GetDeviceScaleFactor() const { |
670 | 450 | QScreen* screen = client_->GetScreen(); | 400 | QScreen* screen = client_->GetScreen(); |
671 | @@ -455,48 +405,6 @@ | |||
672 | 455 | return GetDeviceScaleFactorFromQScreen(screen); | 405 | return GetDeviceScaleFactorFromQScreen(screen); |
673 | 456 | } | 406 | } |
674 | 457 | 407 | ||
675 | 458 | bool WebView::ShouldShowInputPanel() const { | ||
676 | 459 | if (!view_) { | ||
677 | 460 | // Can be called during WebView construction when |view_| is still null. | ||
678 | 461 | return false; | ||
679 | 462 | } | ||
680 | 463 | |||
681 | 464 | if (view_->text_input_type() != ui::TEXT_INPUT_TYPE_NONE && | ||
682 | 465 | view_->show_ime_if_needed() && view_->focused_node_is_editable()) { | ||
683 | 466 | return true; | ||
684 | 467 | } | ||
685 | 468 | |||
686 | 469 | return false; | ||
687 | 470 | } | ||
688 | 471 | |||
689 | 472 | bool WebView::ShouldHideInputPanel() const { | ||
690 | 473 | if (!view_) { | ||
691 | 474 | // Can be called during WebView construction when |view_| is still null. | ||
692 | 475 | return true; | ||
693 | 476 | } | ||
694 | 477 | |||
695 | 478 | if (view_->text_input_type() == ui::TEXT_INPUT_TYPE_NONE && | ||
696 | 479 | !view_->focused_node_is_editable()) { | ||
697 | 480 | return true; | ||
698 | 481 | } | ||
699 | 482 | |||
700 | 483 | return false; | ||
701 | 484 | } | ||
702 | 485 | |||
703 | 486 | void WebView::SetInputPanelVisibility(bool visible) { | ||
704 | 487 | client_->SetInputMethodEnabled(visible); | ||
705 | 488 | |||
706 | 489 | if (!visible) { | ||
707 | 490 | has_input_method_state_ = false; | ||
708 | 491 | } | ||
709 | 492 | |||
710 | 493 | // Do not check whether the input method is currently visible here, to avoid | ||
711 | 494 | // a possible race condition: if hide() and show() are called very quickly | ||
712 | 495 | // in a row, when show() is called the hide() request might not have | ||
713 | 496 | // completed yet, and isVisible() could return true. | ||
714 | 497 | QGuiApplication::inputMethod()->setVisible(visible); | ||
715 | 498 | } | ||
716 | 499 | |||
717 | 500 | void WebView::CommonInit(OxideQFindController* find_controller) { | 408 | void WebView::CommonInit(OxideQFindController* find_controller) { |
718 | 501 | content::WebContents* contents = view_->GetWebContents(); | 409 | content::WebContents* contents = view_->GetWebContents(); |
719 | 502 | 410 | ||
720 | @@ -524,6 +432,10 @@ | |||
721 | 524 | OxideQWebPreferencesPrivate::get(p)->preferences()); | 432 | OxideQWebPreferencesPrivate::get(p)->preferences()); |
722 | 525 | } | 433 | } |
723 | 526 | 434 | ||
724 | 435 | void WebView::SetInputMethodEnabled(bool enabled) { | ||
725 | 436 | client_->SetInputMethodEnabled(enabled); | ||
726 | 437 | } | ||
727 | 438 | |||
728 | 527 | blink::WebScreenInfo WebView::GetScreenInfo() const { | 439 | blink::WebScreenInfo WebView::GetScreenInfo() const { |
729 | 528 | QScreen* screen = client_->GetScreen(); | 440 | QScreen* screen = client_->GetScreen(); |
730 | 529 | if (!screen) { | 441 | if (!screen) { |
731 | @@ -549,15 +461,6 @@ | |||
732 | 549 | return client_->HasFocus(); | 461 | return client_->HasFocus(); |
733 | 550 | } | 462 | } |
734 | 551 | 463 | ||
735 | 552 | bool WebView::IsInputPanelVisible() const { | ||
736 | 553 | QInputMethod* im = QGuiApplication::inputMethod(); | ||
737 | 554 | if (!im) { | ||
738 | 555 | return false; | ||
739 | 556 | } | ||
740 | 557 | |||
741 | 558 | return im->isVisible(); | ||
742 | 559 | } | ||
743 | 560 | |||
744 | 561 | oxide::JavaScriptDialog* WebView::CreateJavaScriptDialog( | 464 | oxide::JavaScriptDialog* WebView::CreateJavaScriptDialog( |
745 | 562 | content::JavaScriptMessageType javascript_message_type) { | 465 | content::JavaScriptMessageType javascript_message_type) { |
746 | 563 | JavaScriptDialogProxyClient::Type type; | 466 | JavaScriptDialogProxyClient::Type type; |
747 | @@ -918,77 +821,8 @@ | |||
748 | 918 | client_->EvictCurrentFrame(); | 821 | client_->EvictCurrentFrame(); |
749 | 919 | } | 822 | } |
750 | 920 | 823 | ||
822 | 921 | void WebView::TextInputStateChanged() { | 824 | oxide::InputMethodContext* WebView::GetInputMethodContext() const { |
823 | 922 | if (!HasFocus()) { | 825 | return input_method_context_.get(); |
753 | 923 | return; | ||
754 | 924 | } | ||
755 | 925 | |||
756 | 926 | if (view_->text_input_type() != ui::TEXT_INPUT_TYPE_NONE) { | ||
757 | 927 | QGuiApplication::inputMethod()->update( | ||
758 | 928 | static_cast<Qt::InputMethodQueries>(Qt::ImQueryInput | Qt::ImHints)); | ||
759 | 929 | } | ||
760 | 930 | |||
761 | 931 | if (ShouldShowInputPanel()) { | ||
762 | 932 | SetInputPanelVisibility(true); | ||
763 | 933 | } else if (ShouldHideInputPanel()) { | ||
764 | 934 | SetInputPanelVisibility(false); | ||
765 | 935 | } | ||
766 | 936 | } | ||
767 | 937 | |||
768 | 938 | void WebView::FocusedNodeChanged() { | ||
769 | 939 | // Work around for https://launchpad.net/bugs/1323743 | ||
770 | 940 | if (QGuiApplication::focusWindow() && | ||
771 | 941 | QGuiApplication::focusWindow()->focusObject()) { | ||
772 | 942 | QGuiApplication::focusWindow()->focusObjectChanged( | ||
773 | 943 | QGuiApplication::focusWindow()->focusObject()); | ||
774 | 944 | } | ||
775 | 945 | |||
776 | 946 | if (ShouldHideInputPanel() && HasFocus()) { | ||
777 | 947 | SetInputPanelVisibility(false); | ||
778 | 948 | } else if (!has_input_method_state_ && ShouldShowInputPanel()) { | ||
779 | 949 | SetInputPanelVisibility(true); | ||
780 | 950 | } else if (has_input_method_state_ && view_->focused_node_is_editable()) { | ||
781 | 951 | QGuiApplication::inputMethod()->reset(); | ||
782 | 952 | } | ||
783 | 953 | } | ||
784 | 954 | |||
785 | 955 | void WebView::SelectionBoundsChanged() { | ||
786 | 956 | if (!HasFocus()) { | ||
787 | 957 | return; | ||
788 | 958 | } | ||
789 | 959 | |||
790 | 960 | QGuiApplication::inputMethod()->update( | ||
791 | 961 | static_cast<Qt::InputMethodQueries>( | ||
792 | 962 | Qt::ImCursorRectangle | ||
793 | 963 | | Qt::ImCursorPosition | ||
794 | 964 | | Qt::ImAnchorPosition | ||
795 | 965 | #if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) | ||
796 | 966 | | Qt::ImTextBeforeCursor | ||
797 | 967 | | Qt::ImTextAfterCursor | ||
798 | 968 | #endif | ||
799 | 969 | )); | ||
800 | 970 | } | ||
801 | 971 | |||
802 | 972 | void WebView::ImeCancelComposition() { | ||
803 | 973 | if (has_input_method_state_) { | ||
804 | 974 | QGuiApplication::inputMethod()->reset(); | ||
805 | 975 | } | ||
806 | 976 | } | ||
807 | 977 | |||
808 | 978 | void WebView::SelectionChanged() { | ||
809 | 979 | if (!HasFocus()) { | ||
810 | 980 | return; | ||
811 | 981 | } | ||
812 | 982 | |||
813 | 983 | QGuiApplication::inputMethod()->update( | ||
814 | 984 | static_cast<Qt::InputMethodQueries>( | ||
815 | 985 | Qt::ImSurroundingText | ||
816 | 986 | | Qt::ImCurrentSelection | ||
817 | 987 | #if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) | ||
818 | 988 | | Qt::ImTextBeforeCursor | ||
819 | 989 | | Qt::ImTextAfterCursor | ||
820 | 990 | #endif | ||
821 | 991 | )); | ||
824 | 992 | } | 826 | } |
825 | 993 | 827 | ||
826 | 994 | void WebView::UpdateCursor(const content::WebCursor& cursor) { | 828 | void WebView::UpdateCursor(const content::WebCursor& cursor) { |
827 | @@ -1189,10 +1023,7 @@ | |||
828 | 1189 | } | 1023 | } |
829 | 1190 | 1024 | ||
830 | 1191 | void WebView::handleFocusEvent(QFocusEvent* event) { | 1025 | void WebView::handleFocusEvent(QFocusEvent* event) { |
835 | 1192 | if (event->gotFocus() && ShouldShowInputPanel()) { | 1026 | input_method_context_->FocusChanged(event); |
832 | 1193 | SetInputPanelVisibility(true); | ||
833 | 1194 | } | ||
834 | 1195 | |||
836 | 1196 | view_->FocusChanged(); | 1027 | view_->FocusChanged(); |
837 | 1197 | } | 1028 | } |
838 | 1198 | 1029 | ||
839 | @@ -1208,62 +1039,7 @@ | |||
840 | 1208 | } | 1039 | } |
841 | 1209 | 1040 | ||
842 | 1210 | void WebView::handleInputMethodEvent(QInputMethodEvent* event) { | 1041 | void WebView::handleInputMethodEvent(QInputMethodEvent* event) { |
899 | 1211 | QString commit_string = event->commitString(); | 1042 | input_method_context_->HandleEvent(event); |
844 | 1212 | |||
845 | 1213 | if (!commit_string.isEmpty()) { | ||
846 | 1214 | gfx::Range replacement_range = gfx::Range::InvalidRange(); | ||
847 | 1215 | if (event->replacementLength() > 0) { | ||
848 | 1216 | replacement_range.set_start(event->replacementStart()); | ||
849 | 1217 | replacement_range.set_end(event->replacementStart() + | ||
850 | 1218 | event->replacementLength()); | ||
851 | 1219 | } | ||
852 | 1220 | view_->ImeCommitText(base::UTF8ToUTF16(commit_string.toStdString()), | ||
853 | 1221 | replacement_range); | ||
854 | 1222 | } | ||
855 | 1223 | |||
856 | 1224 | QString preedit_string = event->preeditString(); | ||
857 | 1225 | |||
858 | 1226 | std::vector<blink::WebCompositionUnderline> underlines; | ||
859 | 1227 | int cursor_position = -1; | ||
860 | 1228 | gfx::Range selection_range = gfx::Range::InvalidRange(); | ||
861 | 1229 | |||
862 | 1230 | Q_FOREACH (const QInputMethodEvent::Attribute& attribute, event->attributes()) { | ||
863 | 1231 | switch (attribute.type) { | ||
864 | 1232 | case QInputMethodEvent::Cursor: | ||
865 | 1233 | if (attribute.length > 0) { | ||
866 | 1234 | cursor_position = attribute.start; | ||
867 | 1235 | } | ||
868 | 1236 | break; | ||
869 | 1237 | case QInputMethodEvent::Selection: | ||
870 | 1238 | selection_range.set_start( | ||
871 | 1239 | qMin(attribute.start, (attribute.start + attribute.length))); | ||
872 | 1240 | selection_range.set_end( | ||
873 | 1241 | qMax(attribute.start, (attribute.start + attribute.length))); | ||
874 | 1242 | break; | ||
875 | 1243 | case QInputMethodEvent::TextFormat: { | ||
876 | 1244 | QTextCharFormat format = | ||
877 | 1245 | attribute.value.value<QTextFormat>().toCharFormat(); | ||
878 | 1246 | blink::WebColor color = format.underlineColor().rgba(); | ||
879 | 1247 | int start = qMin(attribute.start, (attribute.start + attribute.length)); | ||
880 | 1248 | int end = qMax(attribute.start, (attribute.start + attribute.length)); | ||
881 | 1249 | blink::WebCompositionUnderline underline( | ||
882 | 1250 | start, end, color, false, SK_ColorTRANSPARENT); | ||
883 | 1251 | underlines.push_back(underline); | ||
884 | 1252 | break; | ||
885 | 1253 | } | ||
886 | 1254 | default: | ||
887 | 1255 | break; | ||
888 | 1256 | } | ||
889 | 1257 | } | ||
890 | 1258 | |||
891 | 1259 | if (!selection_range.IsValid()) { | ||
892 | 1260 | selection_range = gfx::Range( | ||
893 | 1261 | cursor_position > 0 ? cursor_position : preedit_string.length()); | ||
894 | 1262 | } | ||
895 | 1263 | view_->ImeSetComposingText(base::UTF8ToUTF16(preedit_string.toStdString()), | ||
896 | 1264 | underlines, selection_range); | ||
897 | 1265 | |||
898 | 1266 | has_input_method_state_ = !preedit_string.isEmpty(); | ||
900 | 1267 | } | 1043 | } |
901 | 1268 | 1044 | ||
902 | 1269 | void WebView::handleKeyEvent(QKeyEvent* event) { | 1045 | void WebView::handleKeyEvent(QKeyEvent* event) { |
903 | @@ -1313,42 +1089,7 @@ | |||
904 | 1313 | } | 1089 | } |
905 | 1314 | 1090 | ||
906 | 1315 | QVariant WebView::inputMethodQuery(Qt::InputMethodQuery query) const { | 1091 | QVariant WebView::inputMethodQuery(Qt::InputMethodQuery query) const { |
943 | 1316 | switch (query) { | 1092 | return input_method_context_->Query(query); |
908 | 1317 | case Qt::ImHints: | ||
909 | 1318 | return QVariant(QImHintsFromInputType(view_->text_input_type())); | ||
910 | 1319 | case Qt::ImCursorRectangle: { | ||
911 | 1320 | // XXX: Is this in the right coordinate space? | ||
912 | 1321 | return QRect(view_->caret_rect().x(), view_->caret_rect().y(), | ||
913 | 1322 | view_->caret_rect().width(), view_->caret_rect().height()); | ||
914 | 1323 | } | ||
915 | 1324 | case Qt::ImCursorPosition: | ||
916 | 1325 | return static_cast<int>(view_->selection_cursor_position() & INT_MAX); | ||
917 | 1326 | case Qt::ImSurroundingText: | ||
918 | 1327 | return QString::fromStdString(base::UTF16ToUTF8(view_->GetSelectionText())); | ||
919 | 1328 | case Qt::ImCurrentSelection: | ||
920 | 1329 | return QString::fromStdString(base::UTF16ToUTF8(view_->GetSelectedText())); | ||
921 | 1330 | case Qt::ImAnchorPosition: | ||
922 | 1331 | return static_cast<int>(view_->selection_anchor_position() & INT_MAX); | ||
923 | 1332 | #if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) | ||
924 | 1333 | case Qt::ImTextBeforeCursor: { | ||
925 | 1334 | std::string text = base::UTF16ToUTF8(view_->GetSelectionText()); | ||
926 | 1335 | return QString::fromStdString( | ||
927 | 1336 | text.substr(0, view_->selection_cursor_position())); | ||
928 | 1337 | } | ||
929 | 1338 | case Qt::ImTextAfterCursor: { | ||
930 | 1339 | std::string text = base::UTF16ToUTF8(view_->GetSelectionText()); | ||
931 | 1340 | if (view_->selection_cursor_position() > text.length()) { | ||
932 | 1341 | return QString(); | ||
933 | 1342 | } | ||
934 | 1343 | return QString::fromStdString( | ||
935 | 1344 | text.substr(view_->selection_cursor_position(), std::string::npos)); | ||
936 | 1345 | } | ||
937 | 1346 | #endif | ||
938 | 1347 | default: | ||
939 | 1348 | break; | ||
940 | 1349 | } | ||
941 | 1350 | |||
942 | 1351 | return QVariant(); | ||
944 | 1352 | } | 1093 | } |
945 | 1353 | 1094 | ||
946 | 1354 | void WebView::goBack() { | 1095 | void WebView::goBack() { |
947 | @@ -1689,13 +1430,10 @@ | |||
948 | 1689 | WebView::~WebView() { | 1430 | WebView::~WebView() { |
949 | 1690 | DCHECK(frame_tree_torn_down_); | 1431 | DCHECK(frame_tree_torn_down_); |
950 | 1691 | 1432 | ||
951 | 1433 | input_method_context_->DetachClient(); | ||
952 | 1434 | |||
953 | 1692 | oxide::PermissionRequestDispatcher::FromWebContents( | 1435 | oxide::PermissionRequestDispatcher::FromWebContents( |
954 | 1693 | view_->GetWebContents())->set_client(nullptr); | 1436 | view_->GetWebContents())->set_client(nullptr); |
955 | 1694 | |||
956 | 1695 | QInputMethod* im = QGuiApplication::inputMethod(); | ||
957 | 1696 | if (im) { | ||
958 | 1697 | im->disconnect(this); | ||
959 | 1698 | } | ||
960 | 1699 | } | 1437 | } |
961 | 1700 | 1438 | ||
962 | 1701 | // static | 1439 | // static |
963 | 1702 | 1440 | ||
964 | === modified file 'qt/core/browser/oxide_qt_web_view.h' | |||
965 | --- qt/core/browser/oxide_qt_web_view.h 2015-10-16 21:36:30 +0000 | |||
966 | +++ qt/core/browser/oxide_qt_web_view.h 2015-10-21 17:31:00 +0000 | |||
967 | @@ -20,7 +20,6 @@ | |||
968 | 20 | 20 | ||
969 | 21 | #include <QKeyEvent> | 21 | #include <QKeyEvent> |
970 | 22 | #include <QList> | 22 | #include <QList> |
971 | 23 | #include <QObject> | ||
972 | 24 | #include <QPointer> | 23 | #include <QPointer> |
973 | 25 | #include <QSharedPointer> | 24 | #include <QSharedPointer> |
974 | 26 | #include <QtGlobal> | 25 | #include <QtGlobal> |
975 | @@ -28,6 +27,7 @@ | |||
976 | 28 | #include "base/macros.h" | 27 | #include "base/macros.h" |
977 | 29 | #include "base/memory/scoped_ptr.h" | 28 | #include "base/memory/scoped_ptr.h" |
978 | 30 | 29 | ||
979 | 30 | #include "qt/core/browser/input/oxide_qt_input_method_context_client.h" | ||
980 | 31 | #include "qt/core/browser/oxide_qt_event_utils.h" | 31 | #include "qt/core/browser/oxide_qt_event_utils.h" |
981 | 32 | #include "qt/core/glue/oxide_qt_web_view_proxy.h" | 32 | #include "qt/core/glue/oxide_qt_web_view_proxy.h" |
982 | 33 | #include "shared/browser/oxide_javascript_dialog_manager.h" | 33 | #include "shared/browser/oxide_javascript_dialog_manager.h" |
983 | @@ -53,16 +53,15 @@ | |||
984 | 53 | namespace qt { | 53 | namespace qt { |
985 | 54 | 54 | ||
986 | 55 | class CompositorFrameHandle; | 55 | class CompositorFrameHandle; |
987 | 56 | class InputMethodContext; | ||
988 | 56 | class WebContext; | 57 | class WebContext; |
989 | 57 | class WebViewProxyClient; | 58 | class WebViewProxyClient; |
990 | 58 | 59 | ||
992 | 59 | class WebView : public QObject, | 60 | class WebView : public InputMethodContextClient, |
993 | 60 | public oxide::WebViewClient, | 61 | public oxide::WebViewClient, |
994 | 61 | public oxide::PermissionRequestDispatcherClient, | 62 | public oxide::PermissionRequestDispatcherClient, |
995 | 62 | public oxide::WebFrameTreeObserver, | 63 | public oxide::WebFrameTreeObserver, |
996 | 63 | public WebViewProxy { | 64 | public WebViewProxy { |
997 | 64 | Q_OBJECT | ||
998 | 65 | |||
999 | 66 | public: | 65 | public: |
1000 | 67 | WebView(WebViewProxyClient* client, | 66 | WebView(WebViewProxyClient* client, |
1001 | 68 | OxideQFindController* find_controller, | 67 | OxideQFindController* find_controller, |
1002 | @@ -85,29 +84,24 @@ | |||
1003 | 85 | 84 | ||
1004 | 86 | const oxide::SecurityStatus& GetSecurityStatus() const; | 85 | const oxide::SecurityStatus& GetSecurityStatus() const; |
1005 | 87 | 86 | ||
1006 | 88 | private Q_SLOTS: | ||
1007 | 89 | void OnInputPanelVisibilityChanged(); | ||
1008 | 90 | |||
1009 | 91 | private: | 87 | private: |
1010 | 92 | WebView(WebViewProxyClient* client, | 88 | WebView(WebViewProxyClient* client, |
1011 | 93 | OxideQSecurityStatus* security_status); | 89 | OxideQSecurityStatus* security_status); |
1012 | 94 | 90 | ||
1013 | 95 | float GetDeviceScaleFactor() const; | 91 | float GetDeviceScaleFactor() const; |
1014 | 96 | 92 | ||
1015 | 97 | bool ShouldShowInputPanel() const; | ||
1016 | 98 | bool ShouldHideInputPanel() const; | ||
1017 | 99 | void SetInputPanelVisibility(bool visible); | ||
1018 | 100 | |||
1019 | 101 | void CommonInit(OxideQFindController* find_controller); | 93 | void CommonInit(OxideQFindController* find_controller); |
1020 | 102 | 94 | ||
1021 | 103 | void EnsurePreferences(); | 95 | void EnsurePreferences(); |
1022 | 104 | 96 | ||
1023 | 97 | // InputMethodContextClient implementation | ||
1024 | 98 | void SetInputMethodEnabled(bool enabled); | ||
1025 | 99 | |||
1026 | 105 | // oxide::WebViewClient implementation | 100 | // oxide::WebViewClient implementation |
1027 | 106 | blink::WebScreenInfo GetScreenInfo() const override; | 101 | blink::WebScreenInfo GetScreenInfo() const override; |
1028 | 107 | gfx::Rect GetViewBoundsPix() const override; | 102 | gfx::Rect GetViewBoundsPix() const override; |
1029 | 108 | bool IsVisible() const override; | 103 | bool IsVisible() const override; |
1030 | 109 | bool HasFocus() const override; | 104 | bool HasFocus() const override; |
1031 | 110 | bool IsInputPanelVisible() const override; | ||
1032 | 111 | oxide::JavaScriptDialog* CreateJavaScriptDialog( | 105 | oxide::JavaScriptDialog* CreateJavaScriptDialog( |
1033 | 112 | content::JavaScriptMessageType javascript_message_type) override; | 106 | content::JavaScriptMessageType javascript_message_type) override; |
1034 | 113 | oxide::JavaScriptDialog* CreateBeforeUnloadDialog() override; | 107 | oxide::JavaScriptDialog* CreateBeforeUnloadDialog() override; |
1035 | @@ -169,11 +163,7 @@ | |||
1036 | 169 | oxide::FilePicker* CreateFilePicker(content::RenderViewHost* rvh) override; | 163 | oxide::FilePicker* CreateFilePicker(content::RenderViewHost* rvh) override; |
1037 | 170 | void SwapCompositorFrame() override; | 164 | void SwapCompositorFrame() override; |
1038 | 171 | void EvictCurrentFrame() override; | 165 | void EvictCurrentFrame() override; |
1044 | 172 | void TextInputStateChanged() override; | 166 | oxide::InputMethodContext* GetInputMethodContext() const override; |
1040 | 173 | void FocusedNodeChanged() override; | ||
1041 | 174 | void SelectionBoundsChanged() override; | ||
1042 | 175 | void ImeCancelComposition() override; | ||
1043 | 176 | void SelectionChanged() override; | ||
1045 | 177 | void UpdateCursor(const content::WebCursor& cursor) override; | 167 | void UpdateCursor(const content::WebCursor& cursor) override; |
1046 | 178 | void SecurityStatusChanged(const oxide::SecurityStatus& old) override; | 168 | void SecurityStatusChanged(const oxide::SecurityStatus& old) override; |
1047 | 179 | void OnCertificateError(scoped_ptr<oxide::CertificateError> error) override; | 169 | void OnCertificateError(scoped_ptr<oxide::CertificateError> error) override; |
1048 | @@ -293,12 +283,13 @@ | |||
1049 | 293 | 283 | ||
1050 | 294 | void teardownFrameTree() override; | 284 | void teardownFrameTree() override; |
1051 | 295 | 285 | ||
1052 | 286 | // This must outlive |view_| | ||
1053 | 287 | scoped_ptr<InputMethodContext> input_method_context_; | ||
1054 | 288 | |||
1055 | 296 | scoped_ptr<oxide::WebView> view_; | 289 | scoped_ptr<oxide::WebView> view_; |
1056 | 297 | 290 | ||
1057 | 298 | WebViewProxyClient* client_; | 291 | WebViewProxyClient* client_; |
1058 | 299 | 292 | ||
1059 | 300 | bool has_input_method_state_; | ||
1060 | 301 | |||
1061 | 302 | QPointer<OxideQSecurityStatus> security_status_; | 293 | QPointer<OxideQSecurityStatus> security_status_; |
1062 | 303 | QList<ScriptMessageHandlerProxyHandle*> message_handlers_; | 294 | QList<ScriptMessageHandlerProxyHandle*> message_handlers_; |
1063 | 304 | 295 | ||
1064 | 305 | 296 | ||
1065 | === modified file 'qt/core/core.gyp' | |||
1066 | --- qt/core/core.gyp 2015-09-20 08:39:19 +0000 | |||
1067 | +++ qt/core/core.gyp 2015-10-21 17:31:00 +0000 | |||
1068 | @@ -61,13 +61,16 @@ | |||
1069 | 61 | ], | 61 | ], |
1070 | 62 | 'sources': [ | 62 | 'sources': [ |
1071 | 63 | '<(INTERMEDIATE_DIR)/moc_oxide_qt_browser_platform_integration.cc', | 63 | '<(INTERMEDIATE_DIR)/moc_oxide_qt_browser_platform_integration.cc', |
1073 | 64 | '<(INTERMEDIATE_DIR)/moc_oxide_qt_web_view.cc', | 64 | '<(INTERMEDIATE_DIR)/moc_oxide_qt_input_method_context.cc', |
1074 | 65 | 'api/internal/oxideqmediacapturedevices_p.cc', | 65 | 'api/internal/oxideqmediacapturedevices_p.cc', |
1075 | 66 | 'api/internal/oxideqwebpreferences_p.cc', | 66 | 'api/internal/oxideqwebpreferences_p.cc', |
1076 | 67 | 'app/oxide_qt_main.cc', | 67 | 'app/oxide_qt_main.cc', |
1077 | 68 | 'app/oxide_qt_main.h', | 68 | 'app/oxide_qt_main.h', |
1078 | 69 | 'app/oxide_qt_platform_delegate.cc', | 69 | 'app/oxide_qt_platform_delegate.cc', |
1079 | 70 | 'app/oxide_qt_platform_delegate.h', | 70 | 'app/oxide_qt_platform_delegate.h', |
1080 | 71 | 'browser/input/oxide_qt_input_method_context.cc', | ||
1081 | 72 | 'browser/input/oxide_qt_input_method_context.h', | ||
1082 | 73 | 'browser/input/oxide_qt_input_method_context_client.h', | ||
1083 | 71 | 'browser/oxide_qt_browser_platform_integration.cc', | 74 | 'browser/oxide_qt_browser_platform_integration.cc', |
1084 | 72 | 'browser/oxide_qt_browser_platform_integration.h', | 75 | 'browser/oxide_qt_browser_platform_integration.h', |
1085 | 73 | 'browser/oxide_qt_browser_startup.cc', | 76 | 'browser/oxide_qt_browser_startup.cc', |
1086 | @@ -179,8 +182,8 @@ | |||
1087 | 179 | 'includes': [ 'moc.gypi' ] | 182 | 'includes': [ 'moc.gypi' ] |
1088 | 180 | }, | 183 | }, |
1089 | 181 | { | 184 | { |
1092 | 182 | 'action_name': 'moc_oxide_qt_web_view.cc', | 185 | 'action_name': 'moc_oxide_qt_input_method_context.cc', |
1093 | 183 | 'moc_input': 'browser/oxide_qt_web_view.h', | 186 | 'moc_input': 'browser/input/oxide_qt_input_method_context.h', |
1094 | 184 | 'includes': [ 'moc.gypi' ] | 187 | 'includes': [ 'moc.gypi' ] |
1095 | 185 | }, | 188 | }, |
1096 | 186 | ], | 189 | ], |
1097 | 187 | 190 | ||
1098 | === modified file 'shared/browser/compositor/oxide_compositor.cc' | |||
1099 | --- shared/browser/compositor/oxide_compositor.cc 2015-10-09 09:27:28 +0000 | |||
1100 | +++ shared/browser/compositor/oxide_compositor.cc 2015-10-21 17:31:00 +0000 | |||
1101 | @@ -40,6 +40,7 @@ | |||
1102 | 40 | #include "oxide_compositor_client.h" | 40 | #include "oxide_compositor_client.h" |
1103 | 41 | #include "oxide_compositor_frame_data.h" | 41 | #include "oxide_compositor_frame_data.h" |
1104 | 42 | #include "oxide_compositor_frame_handle.h" | 42 | #include "oxide_compositor_frame_handle.h" |
1105 | 43 | #include "oxide_compositor_observer.h" | ||
1106 | 43 | #include "oxide_compositor_output_surface_gl.h" | 44 | #include "oxide_compositor_output_surface_gl.h" |
1107 | 44 | #include "oxide_compositor_output_surface_software.h" | 45 | #include "oxide_compositor_output_surface_software.h" |
1108 | 45 | #include "oxide_compositor_software_output_device.h" | 46 | #include "oxide_compositor_software_output_device.h" |
1109 | @@ -87,7 +88,6 @@ | |||
1110 | 87 | root_layer_(cc::Layer::Create(cc::LayerSettings())), | 88 | root_layer_(cc::Layer::Create(cc::LayerSettings())), |
1111 | 88 | proxy_(new CompositorThreadProxy(this)), | 89 | proxy_(new CompositorThreadProxy(this)), |
1112 | 89 | next_output_surface_id_(1), | 90 | next_output_surface_id_(1), |
1113 | 90 | lock_count_(0), | ||
1114 | 91 | weak_factory_(this) { | 91 | weak_factory_(this) { |
1115 | 92 | DCHECK(CalledOnValidThread()); | 92 | DCHECK(CalledOnValidThread()); |
1116 | 93 | } | 93 | } |
1117 | @@ -103,29 +103,6 @@ | |||
1118 | 103 | client_->CompositorSwapFrame(handle.get()); | 103 | client_->CompositorSwapFrame(handle.get()); |
1119 | 104 | } | 104 | } |
1120 | 105 | 105 | ||
1121 | 106 | void Compositor::LockCompositor() { | ||
1122 | 107 | DCHECK(CalledOnValidThread()); | ||
1123 | 108 | if (lock_count_++ > 0) { | ||
1124 | 109 | return; | ||
1125 | 110 | } | ||
1126 | 111 | |||
1127 | 112 | if (layer_tree_host_) { | ||
1128 | 113 | layer_tree_host_->SetDeferCommits(true); | ||
1129 | 114 | } | ||
1130 | 115 | } | ||
1131 | 116 | |||
1132 | 117 | void Compositor::UnlockCompositor() { | ||
1133 | 118 | DCHECK(CalledOnValidThread()); | ||
1134 | 119 | DCHECK(lock_count_ > 0); | ||
1135 | 120 | if (--lock_count_ > 0) { | ||
1136 | 121 | return; | ||
1137 | 122 | } | ||
1138 | 123 | |||
1139 | 124 | if (layer_tree_host_) { | ||
1140 | 125 | layer_tree_host_->SetDeferCommits(false); | ||
1141 | 126 | } | ||
1142 | 127 | } | ||
1143 | 128 | |||
1144 | 129 | scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface() { | 106 | scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface() { |
1145 | 130 | DCHECK(CalledOnValidThread()); | 107 | DCHECK(CalledOnValidThread()); |
1146 | 131 | 108 | ||
1147 | @@ -155,6 +132,14 @@ | |||
1148 | 155 | return output.Pass(); | 132 | return output.Pass(); |
1149 | 156 | } | 133 | } |
1150 | 157 | 134 | ||
1151 | 135 | void Compositor::AddObserver(CompositorObserver* observer) { | ||
1152 | 136 | observers_.AddObserver(observer); | ||
1153 | 137 | } | ||
1154 | 138 | |||
1155 | 139 | void Compositor::RemoveObserver(CompositorObserver* observer) { | ||
1156 | 140 | observers_.RemoveObserver(observer); | ||
1157 | 141 | } | ||
1158 | 142 | |||
1159 | 158 | void Compositor::WillBeginMainFrame() {} | 143 | void Compositor::WillBeginMainFrame() {} |
1160 | 159 | void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) {} | 144 | void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) {} |
1161 | 160 | void Compositor::BeginMainFrameNotExpectedSoon() {} | 145 | void Compositor::BeginMainFrameNotExpectedSoon() {} |
1162 | @@ -194,7 +179,7 @@ | |||
1163 | 194 | void Compositor::WillCommit() {} | 179 | void Compositor::WillCommit() {} |
1164 | 195 | 180 | ||
1165 | 196 | void Compositor::DidCommit() { | 181 | void Compositor::DidCommit() { |
1167 | 197 | client_->CompositorDidCommit(); | 182 | FOR_EACH_OBSERVER(CompositorObserver, observers_, CompositorDidCommit()); |
1168 | 198 | } | 183 | } |
1169 | 199 | 184 | ||
1170 | 200 | void Compositor::DidCommitAndDrawFrame() {} | 185 | void Compositor::DidCommitAndDrawFrame() {} |
1171 | @@ -214,7 +199,7 @@ | |||
1172 | 214 | } | 199 | } |
1173 | 215 | 200 | ||
1174 | 216 | Compositor::~Compositor() { | 201 | Compositor::~Compositor() { |
1176 | 217 | CHECK_EQ(lock_count_, 0U); | 202 | FOR_EACH_OBSERVER(CompositorObserver, observers_, OnCompositorDestruction()); |
1177 | 218 | proxy_->CompositorDestroyed(); | 203 | proxy_->CompositorDestroyed(); |
1178 | 219 | } | 204 | } |
1179 | 220 | 205 | ||
1180 | @@ -249,15 +234,15 @@ | |||
1181 | 249 | layer_tree_host_->SetVisible(true); | 234 | layer_tree_host_->SetVisible(true); |
1182 | 250 | layer_tree_host_->SetViewportSize(size_); | 235 | layer_tree_host_->SetViewportSize(size_); |
1183 | 251 | layer_tree_host_->SetDeviceScaleFactor(device_scale_factor_); | 236 | layer_tree_host_->SetDeviceScaleFactor(device_scale_factor_); |
1184 | 252 | |||
1185 | 253 | if (lock_count_ > 0) { | ||
1186 | 254 | layer_tree_host_->SetDeferCommits(true); | ||
1187 | 255 | } | ||
1188 | 256 | } | 237 | } |
1189 | 257 | } | 238 | } |
1190 | 258 | 239 | ||
1191 | 259 | void Compositor::SetDeviceScaleFactor(float scale) { | 240 | void Compositor::SetDeviceScaleFactor(float scale) { |
1192 | 260 | DCHECK(CalledOnValidThread()); | 241 | DCHECK(CalledOnValidThread()); |
1193 | 242 | if (scale == device_scale_factor_) { | ||
1194 | 243 | return; | ||
1195 | 244 | } | ||
1196 | 245 | |||
1197 | 261 | device_scale_factor_ = scale; | 246 | device_scale_factor_ = scale; |
1198 | 262 | 247 | ||
1199 | 263 | if (layer_tree_host_) { | 248 | if (layer_tree_host_) { |
1200 | @@ -281,6 +266,7 @@ | |||
1201 | 281 | 266 | ||
1202 | 282 | void Compositor::SetRootLayer(scoped_refptr<cc::Layer> layer) { | 267 | void Compositor::SetRootLayer(scoped_refptr<cc::Layer> layer) { |
1203 | 283 | DCHECK(CalledOnValidThread()); | 268 | DCHECK(CalledOnValidThread()); |
1204 | 269 | |||
1205 | 284 | root_layer_->RemoveAllChildren(); | 270 | root_layer_->RemoveAllChildren(); |
1206 | 285 | if (layer.get()) { | 271 | if (layer.get()) { |
1207 | 286 | root_layer_->AddChild(layer); | 272 | root_layer_->AddChild(layer); |
1208 | 287 | 273 | ||
1209 | === modified file 'shared/browser/compositor/oxide_compositor.h' | |||
1210 | --- shared/browser/compositor/oxide_compositor.h 2015-08-14 16:32:46 +0000 | |||
1211 | +++ shared/browser/compositor/oxide_compositor.h 2015-10-21 17:31:00 +0000 | |||
1212 | @@ -23,6 +23,7 @@ | |||
1213 | 23 | #include "base/memory/scoped_ptr.h" | 23 | #include "base/memory/scoped_ptr.h" |
1214 | 24 | #include "base/memory/scoped_vector.h" | 24 | #include "base/memory/scoped_vector.h" |
1215 | 25 | #include "base/memory/weak_ptr.h" | 25 | #include "base/memory/weak_ptr.h" |
1216 | 26 | #include "base/observer_list.h" | ||
1217 | 26 | #include "base/threading/non_thread_safe.h" | 27 | #include "base/threading/non_thread_safe.h" |
1218 | 27 | #include "cc/trees/layer_tree_host_client.h" | 28 | #include "cc/trees/layer_tree_host_client.h" |
1219 | 28 | #include "ui/gfx/geometry/size.h" | 29 | #include "ui/gfx/geometry/size.h" |
1220 | @@ -41,7 +42,7 @@ | |||
1221 | 41 | class CompositorClient; | 42 | class CompositorClient; |
1222 | 42 | class CompositorFrameData; | 43 | class CompositorFrameData; |
1223 | 43 | class CompositorFrameHandle; | 44 | class CompositorFrameHandle; |
1225 | 44 | class CompositorLock; | 45 | class CompositorObserver; |
1226 | 45 | class CompositorThreadProxy; | 46 | class CompositorThreadProxy; |
1227 | 46 | 47 | ||
1228 | 47 | class Compositor final : public cc::LayerTreeHostClient, | 48 | class Compositor final : public cc::LayerTreeHostClient, |
1229 | @@ -63,18 +64,18 @@ | |||
1230 | 63 | FrameHandleVector returned_frames); | 64 | FrameHandleVector returned_frames); |
1231 | 64 | 65 | ||
1232 | 65 | private: | 66 | private: |
1234 | 66 | friend class CompositorLock; | 67 | friend class CompositorObserver; |
1235 | 67 | friend class CompositorThreadProxy; | 68 | friend class CompositorThreadProxy; |
1236 | 68 | 69 | ||
1237 | 69 | Compositor(CompositorClient* client); | 70 | Compositor(CompositorClient* client); |
1238 | 70 | 71 | ||
1239 | 71 | void SendSwapCompositorFrameToClient(scoped_ptr<CompositorFrameData> frame); | 72 | void SendSwapCompositorFrameToClient(scoped_ptr<CompositorFrameData> frame); |
1240 | 72 | 73 | ||
1241 | 73 | void LockCompositor(); | ||
1242 | 74 | void UnlockCompositor(); | ||
1243 | 75 | |||
1244 | 76 | scoped_ptr<cc::OutputSurface> CreateOutputSurface(); | 74 | scoped_ptr<cc::OutputSurface> CreateOutputSurface(); |
1245 | 77 | 75 | ||
1246 | 76 | void AddObserver(CompositorObserver* observer); | ||
1247 | 77 | void RemoveObserver(CompositorObserver* observer); | ||
1248 | 78 | |||
1249 | 78 | // cc::LayerTreeHostClient implementation | 79 | // cc::LayerTreeHostClient implementation |
1250 | 79 | void WillBeginMainFrame() final; | 80 | void WillBeginMainFrame() final; |
1251 | 80 | void BeginMainFrame(const cc::BeginFrameArgs& args) final; | 81 | void BeginMainFrame(const cc::BeginFrameArgs& args) final; |
1252 | @@ -112,34 +113,13 @@ | |||
1253 | 112 | 113 | ||
1254 | 113 | uint32 next_output_surface_id_; | 114 | uint32 next_output_surface_id_; |
1255 | 114 | 115 | ||
1257 | 115 | uint32 lock_count_; | 116 | base::ObserverList<CompositorObserver> observers_; |
1258 | 116 | 117 | ||
1259 | 117 | base::WeakPtrFactory<Compositor> weak_factory_; | 118 | base::WeakPtrFactory<Compositor> weak_factory_; |
1260 | 118 | 119 | ||
1261 | 119 | DISALLOW_COPY_AND_ASSIGN(Compositor); | 120 | DISALLOW_COPY_AND_ASSIGN(Compositor); |
1262 | 120 | }; | 121 | }; |
1263 | 121 | 122 | ||
1264 | 122 | class CompositorLock final { | ||
1265 | 123 | public: | ||
1266 | 124 | CompositorLock(Compositor* compositor) | ||
1267 | 125 | : compositor_(compositor) { | ||
1268 | 126 | if (compositor_) { | ||
1269 | 127 | compositor_->LockCompositor(); | ||
1270 | 128 | } | ||
1271 | 129 | } | ||
1272 | 130 | |||
1273 | 131 | ~CompositorLock() { | ||
1274 | 132 | if (compositor_) { | ||
1275 | 133 | compositor_->UnlockCompositor(); | ||
1276 | 134 | } | ||
1277 | 135 | } | ||
1278 | 136 | |||
1279 | 137 | private: | ||
1280 | 138 | Compositor* compositor_; | ||
1281 | 139 | |||
1282 | 140 | DISALLOW_COPY_AND_ASSIGN(CompositorLock); | ||
1283 | 141 | }; | ||
1284 | 142 | |||
1285 | 143 | } // namespace oxide | 123 | } // namespace oxide |
1286 | 144 | 124 | ||
1287 | 145 | #endif // _OXIDE_SHARED_BROWSER_COMPOSITOR_COMPOSITOR_H_ | 125 | #endif // _OXIDE_SHARED_BROWSER_COMPOSITOR_COMPOSITOR_H_ |
1288 | 146 | 126 | ||
1289 | === modified file 'shared/browser/compositor/oxide_compositor_client.h' | |||
1290 | --- shared/browser/compositor/oxide_compositor_client.h 2015-08-14 16:32:46 +0000 | |||
1291 | +++ shared/browser/compositor/oxide_compositor_client.h 2015-10-21 17:31:00 +0000 | |||
1292 | @@ -28,8 +28,6 @@ | |||
1293 | 28 | public: | 28 | public: |
1294 | 29 | virtual ~CompositorClient() {} | 29 | virtual ~CompositorClient() {} |
1295 | 30 | 30 | ||
1296 | 31 | virtual void CompositorDidCommit() = 0; | ||
1297 | 32 | |||
1298 | 33 | virtual void CompositorSwapFrame(CompositorFrameHandle* handle) = 0; | 31 | virtual void CompositorSwapFrame(CompositorFrameHandle* handle) = 0; |
1299 | 34 | }; | 32 | }; |
1300 | 35 | 33 | ||
1301 | 36 | 34 | ||
1302 | === added file 'shared/browser/compositor/oxide_compositor_observer.cc' | |||
1303 | --- shared/browser/compositor/oxide_compositor_observer.cc 1970-01-01 00:00:00 +0000 | |||
1304 | +++ shared/browser/compositor/oxide_compositor_observer.cc 2015-10-21 17:31:00 +0000 | |||
1305 | @@ -0,0 +1,60 @@ | |||
1306 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
1307 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
1308 | 3 | |||
1309 | 4 | // This library is free software; you can redistribute it and/or | ||
1310 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
1311 | 6 | // License as published by the Free Software Foundation; either | ||
1312 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
1313 | 8 | |||
1314 | 9 | // This library is distributed in the hope that it will be useful, | ||
1315 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1316 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1317 | 12 | // Lesser General Public License for more details. | ||
1318 | 13 | |||
1319 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
1320 | 15 | // License along with this library; if not, write to the Free Software | ||
1321 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
1322 | 17 | |||
1323 | 18 | #include "oxide_compositor_observer.h" | ||
1324 | 19 | |||
1325 | 20 | #include "oxide_compositor.h" | ||
1326 | 21 | |||
1327 | 22 | namespace oxide { | ||
1328 | 23 | |||
1329 | 24 | CompositorObserver::CompositorObserver() | ||
1330 | 25 | : compositor_(nullptr) {} | ||
1331 | 26 | |||
1332 | 27 | CompositorObserver::CompositorObserver(Compositor* compositor) | ||
1333 | 28 | : compositor_(compositor) { | ||
1334 | 29 | if (compositor_) { | ||
1335 | 30 | compositor_->AddObserver(this); | ||
1336 | 31 | } | ||
1337 | 32 | } | ||
1338 | 33 | |||
1339 | 34 | void CompositorObserver::Observe(Compositor* compositor) { | ||
1340 | 35 | if (compositor == compositor_) { | ||
1341 | 36 | return; | ||
1342 | 37 | } | ||
1343 | 38 | |||
1344 | 39 | if (compositor_) { | ||
1345 | 40 | compositor_->RemoveObserver(this); | ||
1346 | 41 | } | ||
1347 | 42 | compositor_ = compositor; | ||
1348 | 43 | if (compositor_) { | ||
1349 | 44 | compositor_->AddObserver(this); | ||
1350 | 45 | } | ||
1351 | 46 | } | ||
1352 | 47 | |||
1353 | 48 | void CompositorObserver::OnCompositorDestruction() { | ||
1354 | 49 | compositor_ = nullptr; | ||
1355 | 50 | } | ||
1356 | 51 | |||
1357 | 52 | CompositorObserver::~CompositorObserver() { | ||
1358 | 53 | if (compositor_) { | ||
1359 | 54 | compositor_->RemoveObserver(this); | ||
1360 | 55 | } | ||
1361 | 56 | } | ||
1362 | 57 | |||
1363 | 58 | void CompositorObserver::CompositorDidCommit() {} | ||
1364 | 59 | |||
1365 | 60 | } // namespace oxide | ||
1366 | 0 | 61 | ||
1367 | === added file 'shared/browser/compositor/oxide_compositor_observer.h' | |||
1368 | --- shared/browser/compositor/oxide_compositor_observer.h 1970-01-01 00:00:00 +0000 | |||
1369 | +++ shared/browser/compositor/oxide_compositor_observer.h 2015-10-21 17:31:00 +0000 | |||
1370 | @@ -0,0 +1,49 @@ | |||
1371 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
1372 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
1373 | 3 | |||
1374 | 4 | // This library is free software; you can redistribute it and/or | ||
1375 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
1376 | 6 | // License as published by the Free Software Foundation; either | ||
1377 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
1378 | 8 | |||
1379 | 9 | // This library is distributed in the hope that it will be useful, | ||
1380 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1381 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1382 | 12 | // Lesser General Public License for more details. | ||
1383 | 13 | |||
1384 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
1385 | 15 | // License along with this library; if not, write to the Free Software | ||
1386 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
1387 | 17 | |||
1388 | 18 | #ifndef _OXIDE_SHARED_BROWSER_COMPOSITOR_COMPOSITOR_OBSERVER_H_ | ||
1389 | 19 | #define _OXIDE_SHARED_BROWSER_COMPOSITOR_COMPOSITOR_OBSERVER_H_ | ||
1390 | 20 | |||
1391 | 21 | namespace oxide { | ||
1392 | 22 | |||
1393 | 23 | class Compositor; | ||
1394 | 24 | |||
1395 | 25 | class CompositorObserver { | ||
1396 | 26 | public: | ||
1397 | 27 | virtual ~CompositorObserver(); | ||
1398 | 28 | |||
1399 | 29 | virtual void CompositorDidCommit(); | ||
1400 | 30 | |||
1401 | 31 | protected: | ||
1402 | 32 | CompositorObserver(); | ||
1403 | 33 | CompositorObserver(Compositor* compositor); | ||
1404 | 34 | |||
1405 | 35 | void Observe(Compositor* compositor); | ||
1406 | 36 | |||
1407 | 37 | Compositor* compositor() const { return compositor_; } | ||
1408 | 38 | |||
1409 | 39 | private: | ||
1410 | 40 | friend class Compositor; | ||
1411 | 41 | |||
1412 | 42 | void OnCompositorDestruction(); | ||
1413 | 43 | |||
1414 | 44 | Compositor* compositor_; | ||
1415 | 45 | }; | ||
1416 | 46 | |||
1417 | 47 | } // namespace oxide | ||
1418 | 48 | |||
1419 | 49 | #endif // _OXIDE_SHARED_BROWSER_COMPOSITOR_COMPOSITOR_OBSERVER_H_ | ||
1420 | 0 | 50 | ||
1421 | === added directory 'shared/browser/input' | |||
1422 | === added file 'shared/browser/input/oxide_ime_bridge.cc' | |||
1423 | --- shared/browser/input/oxide_ime_bridge.cc 1970-01-01 00:00:00 +0000 | |||
1424 | +++ shared/browser/input/oxide_ime_bridge.cc 2015-10-21 17:31:00 +0000 | |||
1425 | @@ -0,0 +1,31 @@ | |||
1426 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
1427 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
1428 | 3 | |||
1429 | 4 | // This library is free software; you can redistribute it and/or | ||
1430 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
1431 | 6 | // License as published by the Free Software Foundation; either | ||
1432 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
1433 | 8 | |||
1434 | 9 | // This library is distributed in the hope that it will be useful, | ||
1435 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1436 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1437 | 12 | // Lesser General Public License for more details. | ||
1438 | 13 | |||
1439 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
1440 | 15 | // License along with this library; if not, write to the Free Software | ||
1441 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
1442 | 17 | |||
1443 | 18 | #include "oxide_ime_bridge.h" | ||
1444 | 19 | |||
1445 | 20 | namespace oxide { | ||
1446 | 21 | |||
1447 | 22 | ImeBridge::ImeBridge() | ||
1448 | 23 | : text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | ||
1449 | 24 | show_ime_if_needed_(false), | ||
1450 | 25 | selection_cursor_position_(0), | ||
1451 | 26 | selection_anchor_position_(0), | ||
1452 | 27 | focused_node_is_editable_(false) {} | ||
1453 | 28 | |||
1454 | 29 | ImeBridge::~ImeBridge() {} | ||
1455 | 30 | |||
1456 | 31 | } // namespace oxide | ||
1457 | 0 | 32 | ||
1458 | === added file 'shared/browser/input/oxide_ime_bridge.h' | |||
1459 | --- shared/browser/input/oxide_ime_bridge.h 1970-01-01 00:00:00 +0000 | |||
1460 | +++ shared/browser/input/oxide_ime_bridge.h 2015-10-21 17:31:00 +0000 | |||
1461 | @@ -0,0 +1,84 @@ | |||
1462 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
1463 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
1464 | 3 | |||
1465 | 4 | // This library is free software; you can redistribute it and/or | ||
1466 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
1467 | 6 | // License as published by the Free Software Foundation; either | ||
1468 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
1469 | 8 | |||
1470 | 9 | // This library is distributed in the hope that it will be useful, | ||
1471 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1472 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1473 | 12 | // Lesser General Public License for more details. | ||
1474 | 13 | |||
1475 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
1476 | 15 | // License along with this library; if not, write to the Free Software | ||
1477 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
1478 | 17 | |||
1479 | 18 | #ifndef _OXIDE_SHARED_BROWSER_INPUT_IME_BRIDGE_H_ | ||
1480 | 19 | #define _OXIDE_SHARED_BROWSER_INPUT_IME_BRIDGE_H_ | ||
1481 | 20 | |||
1482 | 21 | #include <vector> | ||
1483 | 22 | |||
1484 | 23 | #include "base/macros.h" | ||
1485 | 24 | #include "base/strings/string16.h" | ||
1486 | 25 | #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | ||
1487 | 26 | #include "ui/base/ime/text_input_type.h" | ||
1488 | 27 | #include "ui/gfx/geometry/rect.h" | ||
1489 | 28 | |||
1490 | 29 | namespace gfx { | ||
1491 | 30 | class Range; | ||
1492 | 31 | } | ||
1493 | 32 | |||
1494 | 33 | namespace oxide { | ||
1495 | 34 | |||
1496 | 35 | // This class contains state for a particular RWHV. InputMethodContext is | ||
1497 | 36 | // connected to one ImeBridge | ||
1498 | 37 | class ImeBridge { | ||
1499 | 38 | public: | ||
1500 | 39 | ImeBridge(); | ||
1501 | 40 | virtual ~ImeBridge(); | ||
1502 | 41 | |||
1503 | 42 | ui::TextInputType text_input_type() const { return text_input_type_; } | ||
1504 | 43 | |||
1505 | 44 | bool show_ime_if_needed() const { return show_ime_if_needed_; } | ||
1506 | 45 | |||
1507 | 46 | gfx::Rect caret_rect() const { return caret_rect_; } | ||
1508 | 47 | |||
1509 | 48 | size_t selection_cursor_position() const { | ||
1510 | 49 | return selection_cursor_position_; | ||
1511 | 50 | } | ||
1512 | 51 | |||
1513 | 52 | size_t selection_anchor_position() const { | ||
1514 | 53 | return selection_anchor_position_; | ||
1515 | 54 | } | ||
1516 | 55 | |||
1517 | 56 | bool focused_node_is_editable() const { | ||
1518 | 57 | return focused_node_is_editable_; | ||
1519 | 58 | } | ||
1520 | 59 | |||
1521 | 60 | virtual base::string16 GetSelectionText() const = 0; | ||
1522 | 61 | virtual base::string16 GetSelectedText() const = 0; | ||
1523 | 62 | |||
1524 | 63 | virtual void CommitText(const base::string16& text, | ||
1525 | 64 | const gfx::Range& replacement_range) = 0; | ||
1526 | 65 | virtual void SetComposingText( | ||
1527 | 66 | const base::string16& text, | ||
1528 | 67 | const std::vector<blink::WebCompositionUnderline>& underlines, | ||
1529 | 68 | const gfx::Range& selection_range) = 0; | ||
1530 | 69 | |||
1531 | 70 | protected: | ||
1532 | 71 | ui::TextInputType text_input_type_; | ||
1533 | 72 | bool show_ime_if_needed_; | ||
1534 | 73 | gfx::Rect caret_rect_; | ||
1535 | 74 | size_t selection_cursor_position_; | ||
1536 | 75 | size_t selection_anchor_position_; | ||
1537 | 76 | bool focused_node_is_editable_; | ||
1538 | 77 | |||
1539 | 78 | private: | ||
1540 | 79 | DISALLOW_COPY_AND_ASSIGN(ImeBridge); | ||
1541 | 80 | }; | ||
1542 | 81 | |||
1543 | 82 | } // namespace oxide | ||
1544 | 83 | |||
1545 | 84 | #endif // _OXIDE_SHARED_BROWSER_INPUT_IME_BRIDGE_H_ | ||
1546 | 0 | 85 | ||
1547 | === added file 'shared/browser/input/oxide_ime_bridge_impl.cc' | |||
1548 | --- shared/browser/input/oxide_ime_bridge_impl.cc 1970-01-01 00:00:00 +0000 | |||
1549 | +++ shared/browser/input/oxide_ime_bridge_impl.cc 2015-10-21 17:31:00 +0000 | |||
1550 | @@ -0,0 +1,157 @@ | |||
1551 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
1552 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
1553 | 3 | |||
1554 | 4 | // This library is free software; you can redistribute it and/or | ||
1555 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
1556 | 6 | // License as published by the Free Software Foundation; either | ||
1557 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
1558 | 8 | |||
1559 | 9 | // This library is distributed in the hope that it will be useful, | ||
1560 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1561 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1562 | 12 | // Lesser General Public License for more details. | ||
1563 | 13 | |||
1564 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
1565 | 15 | // License along with this library; if not, write to the Free Software | ||
1566 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
1567 | 17 | |||
1568 | 18 | #include "oxide_ime_bridge_impl.h" | ||
1569 | 19 | |||
1570 | 20 | #include "content/browser/renderer_host/render_widget_host_impl.h" | ||
1571 | 21 | #include "content/public/browser/native_web_keyboard_event.h" | ||
1572 | 22 | #include "third_party/WebKit/public/web/WebInputEvent.h" | ||
1573 | 23 | #include "ui/events/keycodes/keyboard_codes.h" | ||
1574 | 24 | |||
1575 | 25 | #include "shared/browser/oxide_render_widget_host_view.h" | ||
1576 | 26 | |||
1577 | 27 | #include "oxide_input_method_context.h" | ||
1578 | 28 | |||
1579 | 29 | namespace oxide { | ||
1580 | 30 | |||
1581 | 31 | namespace { | ||
1582 | 32 | |||
1583 | 33 | // Qt input methods don’t generate key events, but a lot of web pages out there | ||
1584 | 34 | // rely on keydown and keyup events to e.g. perform search-as-you-type or | ||
1585 | 35 | // enable/disable a submit button based on the contents of a text input field, | ||
1586 | 36 | // so we send a fake pair of keydown/keyup events. | ||
1587 | 37 | // This mimicks what is done in GtkIMContextWrapper::HandlePreeditChanged(…) | ||
1588 | 38 | // and GtkIMContextWrapper::HandleCommit(…) | ||
1589 | 39 | // (see content/browser/renderer_host/gtk_im_context_wrapper.cc). | ||
1590 | 40 | void SendFakeCompositionKeyEvent(content::RenderWidgetHostImpl* host, | ||
1591 | 41 | blink::WebInputEvent::Type type) { | ||
1592 | 42 | content::NativeWebKeyboardEvent fake_event; | ||
1593 | 43 | fake_event.windowsKeyCode = ui::VKEY_PROCESSKEY; | ||
1594 | 44 | fake_event.skip_in_browser = true; | ||
1595 | 45 | fake_event.type = type; | ||
1596 | 46 | host->ForwardKeyboardEvent(fake_event); | ||
1597 | 47 | } | ||
1598 | 48 | |||
1599 | 49 | } | ||
1600 | 50 | |||
1601 | 51 | base::string16 ImeBridgeImpl::GetSelectionText() const { | ||
1602 | 52 | return rwhv_->selection_text(); | ||
1603 | 53 | } | ||
1604 | 54 | |||
1605 | 55 | base::string16 ImeBridgeImpl::GetSelectedText() const { | ||
1606 | 56 | return rwhv_->GetSelectedText(); | ||
1607 | 57 | } | ||
1608 | 58 | |||
1609 | 59 | void ImeBridgeImpl::CommitText(const base::string16& text, | ||
1610 | 60 | const gfx::Range& replacement_range) { | ||
1611 | 61 | if (!rwhv_->host()) { | ||
1612 | 62 | return; | ||
1613 | 63 | } | ||
1614 | 64 | |||
1615 | 65 | SendFakeCompositionKeyEvent(rwhv_->host(), blink::WebInputEvent::RawKeyDown); | ||
1616 | 66 | rwhv_->host()->ImeConfirmComposition(text, replacement_range, false); | ||
1617 | 67 | SendFakeCompositionKeyEvent(rwhv_->host(), blink::WebInputEvent::KeyUp); | ||
1618 | 68 | } | ||
1619 | 69 | |||
1620 | 70 | void ImeBridgeImpl::SetComposingText( | ||
1621 | 71 | const base::string16& text, | ||
1622 | 72 | const std::vector<blink::WebCompositionUnderline>& underlines, | ||
1623 | 73 | const gfx::Range& selection_range) { | ||
1624 | 74 | if (!rwhv_->host()) { | ||
1625 | 75 | return; | ||
1626 | 76 | } | ||
1627 | 77 | |||
1628 | 78 | SendFakeCompositionKeyEvent(rwhv_->host(), blink::WebInputEvent::RawKeyDown); | ||
1629 | 79 | rwhv_->host()->ImeSetComposition(text, | ||
1630 | 80 | underlines, | ||
1631 | 81 | selection_range.start(), | ||
1632 | 82 | selection_range.end()); | ||
1633 | 83 | SendFakeCompositionKeyEvent(rwhv_->host(), blink::WebInputEvent::KeyUp); | ||
1634 | 84 | } | ||
1635 | 85 | |||
1636 | 86 | ImeBridgeImpl::ImeBridgeImpl(RenderWidgetHostView* rwhv) | ||
1637 | 87 | : rwhv_(rwhv), | ||
1638 | 88 | context_(nullptr) {} | ||
1639 | 89 | |||
1640 | 90 | ImeBridgeImpl::~ImeBridgeImpl() { | ||
1641 | 91 | SetContext(nullptr); | ||
1642 | 92 | } | ||
1643 | 93 | |||
1644 | 94 | void ImeBridgeImpl::SetContext(InputMethodContext* context) { | ||
1645 | 95 | if (context_) { | ||
1646 | 96 | DCHECK_EQ(context_->ime_bridge(), this); | ||
1647 | 97 | context_->SetImeBridge(nullptr); | ||
1648 | 98 | } | ||
1649 | 99 | context_ = context; | ||
1650 | 100 | if (context_) { | ||
1651 | 101 | DCHECK(!context_->ime_bridge()); | ||
1652 | 102 | context_->SetImeBridge(this); | ||
1653 | 103 | } | ||
1654 | 104 | } | ||
1655 | 105 | |||
1656 | 106 | void ImeBridgeImpl::TextInputStateChanged(ui::TextInputType type, | ||
1657 | 107 | bool show_ime_if_needed) { | ||
1658 | 108 | if (type == text_input_type_ && | ||
1659 | 109 | show_ime_if_needed == show_ime_if_needed_) { | ||
1660 | 110 | return; | ||
1661 | 111 | } | ||
1662 | 112 | |||
1663 | 113 | text_input_type_ = type; | ||
1664 | 114 | show_ime_if_needed_ = show_ime_if_needed; | ||
1665 | 115 | |||
1666 | 116 | if (!context_) { | ||
1667 | 117 | return; | ||
1668 | 118 | } | ||
1669 | 119 | |||
1670 | 120 | context_->TextInputStateChanged(); | ||
1671 | 121 | } | ||
1672 | 122 | |||
1673 | 123 | void ImeBridgeImpl::SelectionBoundsChanged(const gfx::Rect& caret_rect, | ||
1674 | 124 | size_t selection_cursor_position, | ||
1675 | 125 | size_t selection_anchor_position) { | ||
1676 | 126 | if (caret_rect == caret_rect_ && | ||
1677 | 127 | selection_cursor_position == selection_cursor_position_ && | ||
1678 | 128 | selection_anchor_position == selection_anchor_position_) { | ||
1679 | 129 | return; | ||
1680 | 130 | } | ||
1681 | 131 | |||
1682 | 132 | caret_rect_ = caret_rect; | ||
1683 | 133 | selection_cursor_position_ = selection_cursor_position; | ||
1684 | 134 | selection_anchor_position_ = selection_anchor_position; | ||
1685 | 135 | |||
1686 | 136 | if (!context_) { | ||
1687 | 137 | return; | ||
1688 | 138 | } | ||
1689 | 139 | |||
1690 | 140 | context_->SelectionBoundsChanged(); | ||
1691 | 141 | } | ||
1692 | 142 | |||
1693 | 143 | void ImeBridgeImpl::FocusedNodeChanged(bool is_editable_node) { | ||
1694 | 144 | if (is_editable_node == focused_node_is_editable_) { | ||
1695 | 145 | return; | ||
1696 | 146 | } | ||
1697 | 147 | |||
1698 | 148 | focused_node_is_editable_ = is_editable_node; | ||
1699 | 149 | |||
1700 | 150 | if (!context_) { | ||
1701 | 151 | return; | ||
1702 | 152 | } | ||
1703 | 153 | |||
1704 | 154 | context_->FocusedNodeChanged(); | ||
1705 | 155 | } | ||
1706 | 156 | |||
1707 | 157 | } // namespace oxide | ||
1708 | 0 | 158 | ||
1709 | === added file 'shared/browser/input/oxide_ime_bridge_impl.h' | |||
1710 | --- shared/browser/input/oxide_ime_bridge_impl.h 1970-01-01 00:00:00 +0000 | |||
1711 | +++ shared/browser/input/oxide_ime_bridge_impl.h 2015-10-21 17:31:00 +0000 | |||
1712 | @@ -0,0 +1,69 @@ | |||
1713 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
1714 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
1715 | 3 | |||
1716 | 4 | // This library is free software; you can redistribute it and/or | ||
1717 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
1718 | 6 | // License as published by the Free Software Foundation; either | ||
1719 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
1720 | 8 | |||
1721 | 9 | // This library is distributed in the hope that it will be useful, | ||
1722 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1723 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1724 | 12 | // Lesser General Public License for more details. | ||
1725 | 13 | |||
1726 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
1727 | 15 | // License along with this library; if not, write to the Free Software | ||
1728 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
1729 | 17 | |||
1730 | 18 | #ifndef _OXIDE_SHARED_BROWSER_INPUT_IME_BRIDGE_IMPL_H_ | ||
1731 | 19 | #define _OXIDE_SHARED_BROWSER_INPUT_IME_BRIDGE_IMPL_H_ | ||
1732 | 20 | |||
1733 | 21 | #include "base/macros.h" | ||
1734 | 22 | #include "ui/base/ime/text_input_type.h" | ||
1735 | 23 | |||
1736 | 24 | #include "shared/browser/input/oxide_ime_bridge.h" | ||
1737 | 25 | |||
1738 | 26 | namespace gfx { | ||
1739 | 27 | class Rect; | ||
1740 | 28 | } | ||
1741 | 29 | |||
1742 | 30 | namespace oxide { | ||
1743 | 31 | |||
1744 | 32 | class InputMethodContext; | ||
1745 | 33 | class RenderWidgetHostView; | ||
1746 | 34 | |||
1747 | 35 | class ImeBridgeImpl : public ImeBridge { | ||
1748 | 36 | public: | ||
1749 | 37 | ImeBridgeImpl(RenderWidgetHostView* rwhv); | ||
1750 | 38 | ~ImeBridgeImpl() override; | ||
1751 | 39 | |||
1752 | 40 | InputMethodContext* context() const { return context_; } | ||
1753 | 41 | void SetContext(InputMethodContext* context); | ||
1754 | 42 | |||
1755 | 43 | void TextInputStateChanged(ui::TextInputType type, | ||
1756 | 44 | bool show_ime_if_needed); | ||
1757 | 45 | void SelectionBoundsChanged(const gfx::Rect& caret_rect, | ||
1758 | 46 | size_t selection_cursor_position, | ||
1759 | 47 | size_t selection_anchor_position); | ||
1760 | 48 | void FocusedNodeChanged(bool is_editable_node); | ||
1761 | 49 | |||
1762 | 50 | private: | ||
1763 | 51 | base::string16 GetSelectionText() const override; | ||
1764 | 52 | base::string16 GetSelectedText() const override; | ||
1765 | 53 | void CommitText(const base::string16& text, | ||
1766 | 54 | const gfx::Range& replacement_range) override; | ||
1767 | 55 | void SetComposingText( | ||
1768 | 56 | const base::string16& text, | ||
1769 | 57 | const std::vector<blink::WebCompositionUnderline>& underlines, | ||
1770 | 58 | const gfx::Range& selection_range) override; | ||
1771 | 59 | |||
1772 | 60 | RenderWidgetHostView* rwhv_; // Owns us | ||
1773 | 61 | |||
1774 | 62 | InputMethodContext* context_; | ||
1775 | 63 | |||
1776 | 64 | DISALLOW_COPY_AND_ASSIGN(ImeBridgeImpl); | ||
1777 | 65 | }; | ||
1778 | 66 | |||
1779 | 67 | } // namespace oxide | ||
1780 | 68 | |||
1781 | 69 | #endif // _OXIDE_SHARED_BROWSER_INPUT_IME_BRIDGE_IMPL_H_ | ||
1782 | 0 | 70 | ||
1783 | === added file 'shared/browser/input/oxide_input_method_context.cc' | |||
1784 | --- shared/browser/input/oxide_input_method_context.cc 1970-01-01 00:00:00 +0000 | |||
1785 | +++ shared/browser/input/oxide_input_method_context.cc 2015-10-21 17:31:00 +0000 | |||
1786 | @@ -0,0 +1,69 @@ | |||
1787 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
1788 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
1789 | 3 | |||
1790 | 4 | // This library is free software; you can redistribute it and/or | ||
1791 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
1792 | 6 | // License as published by the Free Software Foundation; either | ||
1793 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
1794 | 8 | |||
1795 | 9 | // This library is distributed in the hope that it will be useful, | ||
1796 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1797 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1798 | 12 | // Lesser General Public License for more details. | ||
1799 | 13 | |||
1800 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
1801 | 15 | // License along with this library; if not, write to the Free Software | ||
1802 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
1803 | 17 | |||
1804 | 18 | #include "oxide_input_method_context.h" | ||
1805 | 19 | |||
1806 | 20 | #include "oxide_input_method_context_observer.h" | ||
1807 | 21 | |||
1808 | 22 | namespace oxide { | ||
1809 | 23 | |||
1810 | 24 | void InputMethodContext::NotifyInputPanelVisibilityChanged() { | ||
1811 | 25 | FOR_EACH_OBSERVER(InputMethodContextObserver, | ||
1812 | 26 | observers_, | ||
1813 | 27 | InputPanelVisibilityChanged()); | ||
1814 | 28 | } | ||
1815 | 29 | |||
1816 | 30 | void InputMethodContext::SetImeBridge(ImeBridge* bridge) { | ||
1817 | 31 | ime_bridge_ = bridge; | ||
1818 | 32 | |||
1819 | 33 | CancelComposition(); | ||
1820 | 34 | |||
1821 | 35 | // XXX: This is a bit of a hammer | ||
1822 | 36 | TextInputStateChanged(); | ||
1823 | 37 | SelectionBoundsChanged(); | ||
1824 | 38 | SelectionChanged(); | ||
1825 | 39 | FocusedNodeChanged(); | ||
1826 | 40 | } | ||
1827 | 41 | |||
1828 | 42 | void InputMethodContext::AddObserver(InputMethodContextObserver* observer) { | ||
1829 | 43 | observers_.AddObserver(observer); | ||
1830 | 44 | } | ||
1831 | 45 | |||
1832 | 46 | void InputMethodContext::RemoveObserver(InputMethodContextObserver* observer) { | ||
1833 | 47 | observers_.RemoveObserver(observer); | ||
1834 | 48 | } | ||
1835 | 49 | |||
1836 | 50 | InputMethodContext::InputMethodContext() | ||
1837 | 51 | : ime_bridge_(nullptr) {} | ||
1838 | 52 | |||
1839 | 53 | InputMethodContext::~InputMethodContext() { | ||
1840 | 54 | FOR_EACH_OBSERVER(InputMethodContextObserver, | ||
1841 | 55 | observers_, | ||
1842 | 56 | OnInputMethodContextDestruction()); | ||
1843 | 57 | } | ||
1844 | 58 | |||
1845 | 59 | bool InputMethodContext::IsInputPanelVisible() const { | ||
1846 | 60 | return false; | ||
1847 | 61 | } | ||
1848 | 62 | |||
1849 | 63 | void InputMethodContext::TextInputStateChanged() {} | ||
1850 | 64 | void InputMethodContext::SelectionBoundsChanged() {} | ||
1851 | 65 | void InputMethodContext::SelectionChanged() {} | ||
1852 | 66 | void InputMethodContext::CancelComposition() {} | ||
1853 | 67 | void InputMethodContext::FocusedNodeChanged() {} | ||
1854 | 68 | |||
1855 | 69 | } // namespace oxide | ||
1856 | 0 | 70 | ||
1857 | === added file 'shared/browser/input/oxide_input_method_context.h' | |||
1858 | --- shared/browser/input/oxide_input_method_context.h 1970-01-01 00:00:00 +0000 | |||
1859 | +++ shared/browser/input/oxide_input_method_context.h 2015-10-21 17:31:00 +0000 | |||
1860 | @@ -0,0 +1,69 @@ | |||
1861 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
1862 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
1863 | 3 | |||
1864 | 4 | // This library is free software; you can redistribute it and/or | ||
1865 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
1866 | 6 | // License as published by the Free Software Foundation; either | ||
1867 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
1868 | 8 | |||
1869 | 9 | // This library is distributed in the hope that it will be useful, | ||
1870 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1871 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1872 | 12 | // Lesser General Public License for more details. | ||
1873 | 13 | |||
1874 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
1875 | 15 | // License along with this library; if not, write to the Free Software | ||
1876 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
1877 | 17 | |||
1878 | 18 | #ifndef _OXIDE_SHARED_BROWSER_INPUT_INPUT_METHOD_CONTEXT_H_ | ||
1879 | 19 | #define _OXIDE_SHARED_BROWSER_INPUT_INPUT_METHOD_CONTEXT_H_ | ||
1880 | 20 | |||
1881 | 21 | #include "base/macros.h" | ||
1882 | 22 | #include "base/observer_list.h" | ||
1883 | 23 | |||
1884 | 24 | namespace oxide { | ||
1885 | 25 | |||
1886 | 26 | class ImeBridge; | ||
1887 | 27 | class ImeBridgeImpl; | ||
1888 | 28 | class InputMethodContextObserver; | ||
1889 | 29 | |||
1890 | 30 | // This class is the interface from ImeBridgeImpl to the toolkit provided | ||
1891 | 31 | // input method context, and provides a way for the toolkit layer to access | ||
1892 | 32 | // the currently connected ImeBridge | ||
1893 | 33 | class InputMethodContext { | ||
1894 | 34 | public: | ||
1895 | 35 | InputMethodContext(); | ||
1896 | 36 | virtual ~InputMethodContext(); | ||
1897 | 37 | |||
1898 | 38 | virtual bool IsInputPanelVisible() const; | ||
1899 | 39 | |||
1900 | 40 | virtual void TextInputStateChanged(); | ||
1901 | 41 | virtual void SelectionBoundsChanged(); | ||
1902 | 42 | virtual void SelectionChanged(); | ||
1903 | 43 | virtual void CancelComposition(); | ||
1904 | 44 | virtual void FocusedNodeChanged(); | ||
1905 | 45 | |||
1906 | 46 | protected: | ||
1907 | 47 | ImeBridge* ime_bridge() const { return ime_bridge_; } | ||
1908 | 48 | |||
1909 | 49 | void NotifyInputPanelVisibilityChanged(); | ||
1910 | 50 | |||
1911 | 51 | private: | ||
1912 | 52 | friend class ImeBridgeImpl; | ||
1913 | 53 | friend class InputMethodContextObserver; | ||
1914 | 54 | |||
1915 | 55 | void SetImeBridge(ImeBridge* bridge); | ||
1916 | 56 | |||
1917 | 57 | void AddObserver(InputMethodContextObserver* observer); | ||
1918 | 58 | void RemoveObserver(InputMethodContextObserver* observer); | ||
1919 | 59 | |||
1920 | 60 | ImeBridge* ime_bridge_; | ||
1921 | 61 | |||
1922 | 62 | base::ObserverList<InputMethodContextObserver> observers_; | ||
1923 | 63 | |||
1924 | 64 | DISALLOW_COPY_AND_ASSIGN(InputMethodContext); | ||
1925 | 65 | }; | ||
1926 | 66 | |||
1927 | 67 | } // namespace oxide | ||
1928 | 68 | |||
1929 | 69 | #endif // _OXIDE_SHARED_BROWSER_INPUT_INPUT_METHOD_CONTEXT_H_ | ||
1930 | 0 | 70 | ||
1931 | === added file 'shared/browser/input/oxide_input_method_context_observer.cc' | |||
1932 | --- shared/browser/input/oxide_input_method_context_observer.cc 1970-01-01 00:00:00 +0000 | |||
1933 | +++ shared/browser/input/oxide_input_method_context_observer.cc 2015-10-21 17:31:00 +0000 | |||
1934 | @@ -0,0 +1,61 @@ | |||
1935 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
1936 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
1937 | 3 | |||
1938 | 4 | // This library is free software; you can redistribute it and/or | ||
1939 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
1940 | 6 | // License as published by the Free Software Foundation; either | ||
1941 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
1942 | 8 | |||
1943 | 9 | // This library is distributed in the hope that it will be useful, | ||
1944 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1945 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1946 | 12 | // Lesser General Public License for more details. | ||
1947 | 13 | |||
1948 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
1949 | 15 | // License along with this library; if not, write to the Free Software | ||
1950 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
1951 | 17 | |||
1952 | 18 | #include "oxide_input_method_context_observer.h" | ||
1953 | 19 | |||
1954 | 20 | #include "oxide_input_method_context.h" | ||
1955 | 21 | |||
1956 | 22 | namespace oxide { | ||
1957 | 23 | |||
1958 | 24 | InputMethodContextObserver::InputMethodContextObserver() | ||
1959 | 25 | : im_context_(nullptr) {} | ||
1960 | 26 | |||
1961 | 27 | InputMethodContextObserver::InputMethodContextObserver( | ||
1962 | 28 | InputMethodContext* context) | ||
1963 | 29 | : im_context_(context) { | ||
1964 | 30 | if (context) { | ||
1965 | 31 | context->AddObserver(this); | ||
1966 | 32 | } | ||
1967 | 33 | } | ||
1968 | 34 | |||
1969 | 35 | void InputMethodContextObserver::Observe(InputMethodContext* context) { | ||
1970 | 36 | if (context == im_context_) { | ||
1971 | 37 | return; | ||
1972 | 38 | } | ||
1973 | 39 | |||
1974 | 40 | if (im_context_) { | ||
1975 | 41 | im_context_->RemoveObserver(this); | ||
1976 | 42 | } | ||
1977 | 43 | im_context_ = context; | ||
1978 | 44 | if (im_context_) { | ||
1979 | 45 | im_context_->AddObserver(this); | ||
1980 | 46 | } | ||
1981 | 47 | } | ||
1982 | 48 | |||
1983 | 49 | void InputMethodContextObserver::OnInputMethodContextDestruction() { | ||
1984 | 50 | im_context_ = nullptr; | ||
1985 | 51 | } | ||
1986 | 52 | |||
1987 | 53 | InputMethodContextObserver::~InputMethodContextObserver() { | ||
1988 | 54 | if (im_context_) { | ||
1989 | 55 | im_context_->RemoveObserver(this); | ||
1990 | 56 | } | ||
1991 | 57 | } | ||
1992 | 58 | |||
1993 | 59 | void InputMethodContextObserver::InputPanelVisibilityChanged() {} | ||
1994 | 60 | |||
1995 | 61 | } // namespace oxide | ||
1996 | 0 | 62 | ||
1997 | === added file 'shared/browser/input/oxide_input_method_context_observer.h' | |||
1998 | --- shared/browser/input/oxide_input_method_context_observer.h 1970-01-01 00:00:00 +0000 | |||
1999 | +++ shared/browser/input/oxide_input_method_context_observer.h 2015-10-21 17:31:00 +0000 | |||
2000 | @@ -0,0 +1,49 @@ | |||
2001 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
2002 | 2 | // Copyright (C) 2015 Canonical Ltd. | ||
2003 | 3 | |||
2004 | 4 | // This library is free software; you can redistribute it and/or | ||
2005 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
2006 | 6 | // License as published by the Free Software Foundation; either | ||
2007 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
2008 | 8 | |||
2009 | 9 | // This library is distributed in the hope that it will be useful, | ||
2010 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2011 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2012 | 12 | // Lesser General Public License for more details. | ||
2013 | 13 | |||
2014 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
2015 | 15 | // License along with this library; if not, write to the Free Software | ||
2016 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
2017 | 17 | |||
2018 | 18 | #ifndef _OXIDE_SHARED_BROWSER_INPUT_INPUT_METHOD_CONTEXT_OBSERVER_H_ | ||
2019 | 19 | #define _OXIDE_SHARED_BROWSER_INPUT_INPUT_METHOD_CONTEXT_OBSERVER_H_ | ||
2020 | 20 | |||
2021 | 21 | namespace oxide { | ||
2022 | 22 | |||
2023 | 23 | class InputMethodContext; | ||
2024 | 24 | |||
2025 | 25 | class InputMethodContextObserver { | ||
2026 | 26 | public: | ||
2027 | 27 | virtual ~InputMethodContextObserver(); | ||
2028 | 28 | |||
2029 | 29 | virtual void InputPanelVisibilityChanged(); | ||
2030 | 30 | |||
2031 | 31 | protected: | ||
2032 | 32 | InputMethodContextObserver(); | ||
2033 | 33 | InputMethodContextObserver(InputMethodContext* context); | ||
2034 | 34 | |||
2035 | 35 | void Observe(InputMethodContext* context); | ||
2036 | 36 | |||
2037 | 37 | InputMethodContext* im_context() const { return im_context_; } | ||
2038 | 38 | |||
2039 | 39 | private: | ||
2040 | 40 | friend class InputMethodContext; | ||
2041 | 41 | |||
2042 | 42 | void OnInputMethodContextDestruction(); | ||
2043 | 43 | |||
2044 | 44 | InputMethodContext* im_context_; | ||
2045 | 45 | }; | ||
2046 | 46 | |||
2047 | 47 | } // namespace oxide | ||
2048 | 48 | |||
2049 | 49 | #endif // _OXIDE_SHARED_BROWSER_INPUT_INPUT_METHOD_CONTEXT_OBSERVER_H_ | ||
2050 | 0 | 50 | ||
2051 | === modified file 'shared/browser/oxide_render_widget_host_view.cc' | |||
2052 | --- shared/browser/oxide_render_widget_host_view.cc 2015-09-29 08:25:11 +0000 | |||
2053 | +++ shared/browser/oxide_render_widget_host_view.cc 2015-10-21 17:31:00 +0000 | |||
2054 | @@ -40,13 +40,13 @@ | |||
2055 | 40 | #include "ui/gfx/geometry/size_conversions.h" | 40 | #include "ui/gfx/geometry/size_conversions.h" |
2056 | 41 | 41 | ||
2057 | 42 | #include "shared/browser/compositor/oxide_compositor.h" | 42 | #include "shared/browser/compositor/oxide_compositor.h" |
2059 | 43 | #include "shared/browser/compositor/oxide_compositor_utils.h" | 43 | #include "shared/browser/input/oxide_input_method_context.h" |
2060 | 44 | 44 | ||
2061 | 45 | #include "oxide_browser_platform_integration.h" | 45 | #include "oxide_browser_platform_integration.h" |
2062 | 46 | #include "oxide_browser_process_main.h" | 46 | #include "oxide_browser_process_main.h" |
2063 | 47 | #include "oxide_event_utils.h" | 47 | #include "oxide_event_utils.h" |
2064 | 48 | #include "oxide_renderer_frame_evictor.h" | 48 | #include "oxide_renderer_frame_evictor.h" |
2066 | 49 | #include "oxide_render_widget_host_view_delegate.h" | 49 | #include "oxide_render_widget_host_view_container.h" |
2067 | 50 | 50 | ||
2068 | 51 | namespace oxide { | 51 | namespace oxide { |
2069 | 52 | 52 | ||
2070 | @@ -81,43 +81,35 @@ | |||
2071 | 81 | void RenderWidgetHostView::OnTextInputStateChanged( | 81 | void RenderWidgetHostView::OnTextInputStateChanged( |
2072 | 82 | ui::TextInputType type, | 82 | ui::TextInputType type, |
2073 | 83 | bool show_ime_if_needed) { | 83 | bool show_ime_if_needed) { |
2084 | 84 | if (type != current_text_input_type_ || | 84 | ime_bridge_.TextInputStateChanged(type, show_ime_if_needed); |
2075 | 85 | show_ime_if_needed != show_ime_if_needed_) { | ||
2076 | 86 | current_text_input_type_ = type; | ||
2077 | 87 | show_ime_if_needed_ = show_ime_if_needed; | ||
2078 | 88 | |||
2079 | 89 | if (delegate_) { | ||
2080 | 90 | delegate_->TextInputStateChanged(current_text_input_type_, | ||
2081 | 91 | show_ime_if_needed_); | ||
2082 | 92 | } | ||
2083 | 93 | } | ||
2085 | 94 | } | 85 | } |
2086 | 95 | 86 | ||
2087 | 96 | void RenderWidgetHostView::OnSelectionBoundsChanged( | 87 | void RenderWidgetHostView::OnSelectionBoundsChanged( |
2088 | 97 | const gfx::Rect& anchor_rect, | 88 | const gfx::Rect& anchor_rect, |
2089 | 98 | const gfx::Rect& focus_rect, | 89 | const gfx::Rect& focus_rect, |
2090 | 99 | bool is_anchor_first) { | 90 | bool is_anchor_first) { |
2092 | 100 | caret_rect_ = gfx::UnionRects(anchor_rect, focus_rect); | 91 | gfx::Rect caret_rect = gfx::UnionRects(anchor_rect, focus_rect); |
2093 | 92 | |||
2094 | 93 | size_t selection_cursor_position = 0; | ||
2095 | 94 | size_t selection_anchor_position = 0; | ||
2096 | 101 | 95 | ||
2097 | 102 | if (selection_range_.IsValid()) { | 96 | if (selection_range_.IsValid()) { |
2098 | 103 | if (is_anchor_first) { | 97 | if (is_anchor_first) { |
2100 | 104 | selection_cursor_position_ = | 98 | selection_cursor_position = |
2101 | 105 | selection_range_.GetMax() - selection_text_offset_; | 99 | selection_range_.GetMax() - selection_text_offset_; |
2103 | 106 | selection_anchor_position_ = | 100 | selection_anchor_position = |
2104 | 107 | selection_range_.GetMin() - selection_text_offset_; | 101 | selection_range_.GetMin() - selection_text_offset_; |
2105 | 108 | } else { | 102 | } else { |
2107 | 109 | selection_cursor_position_ = | 103 | selection_cursor_position = |
2108 | 110 | selection_range_.GetMin() - selection_text_offset_; | 104 | selection_range_.GetMin() - selection_text_offset_; |
2110 | 111 | selection_anchor_position_ = | 105 | selection_anchor_position = |
2111 | 112 | selection_range_.GetMax() - selection_text_offset_; | 106 | selection_range_.GetMax() - selection_text_offset_; |
2112 | 113 | } | 107 | } |
2113 | 114 | } | 108 | } |
2114 | 115 | 109 | ||
2120 | 116 | if (delegate_) { | 110 | ime_bridge_.SelectionBoundsChanged(caret_rect, |
2121 | 117 | delegate_->SelectionBoundsChanged(caret_rect_, | 111 | selection_cursor_position, |
2122 | 118 | selection_cursor_position_, | 112 | selection_anchor_position); |
2118 | 119 | selection_anchor_position_); | ||
2119 | 120 | } | ||
2123 | 121 | } | 113 | } |
2124 | 122 | 114 | ||
2125 | 123 | void RenderWidgetHostView::SelectionChanged(const base::string16& text, | 115 | void RenderWidgetHostView::SelectionChanged(const base::string16& text, |
2126 | @@ -136,17 +128,17 @@ | |||
2127 | 136 | 128 | ||
2128 | 137 | content::RenderWidgetHostViewBase::SelectionChanged(text, offset, range); | 129 | content::RenderWidgetHostViewBase::SelectionChanged(text, offset, range); |
2129 | 138 | 130 | ||
2132 | 139 | if (delegate_) { | 131 | if (ime_bridge_.context()) { |
2133 | 140 | delegate_->SelectionChanged(); | 132 | ime_bridge_.context()->SelectionChanged(); |
2134 | 141 | } | 133 | } |
2135 | 142 | } | 134 | } |
2136 | 143 | 135 | ||
2137 | 144 | gfx::Size RenderWidgetHostView::GetPhysicalBackingSize() const { | 136 | gfx::Size RenderWidgetHostView::GetPhysicalBackingSize() const { |
2139 | 145 | if (!delegate_) { | 137 | if (!container_) { |
2140 | 146 | return gfx::Size(); | 138 | return gfx::Size(); |
2141 | 147 | } | 139 | } |
2142 | 148 | 140 | ||
2144 | 149 | return delegate_->GetViewSizePix(); | 141 | return container_->GetViewSizePix(); |
2145 | 150 | } | 142 | } |
2146 | 151 | 143 | ||
2147 | 152 | bool RenderWidgetHostView::DoTopControlsShrinkBlinkSize() const { | 144 | bool RenderWidgetHostView::DoTopControlsShrinkBlinkSize() const { |
2148 | @@ -154,18 +146,15 @@ | |||
2149 | 154 | } | 146 | } |
2150 | 155 | 147 | ||
2151 | 156 | float RenderWidgetHostView::GetTopControlsHeight() const { | 148 | float RenderWidgetHostView::GetTopControlsHeight() const { |
2153 | 157 | if (!delegate_) { | 149 | if (!container_) { |
2154 | 158 | return 0.0f; | 150 | return 0.0f; |
2155 | 159 | } | 151 | } |
2156 | 160 | 152 | ||
2158 | 161 | return delegate_->GetLocationBarHeightDip(); | 153 | return container_->GetLocationBarHeightDip(); |
2159 | 162 | } | 154 | } |
2160 | 163 | 155 | ||
2161 | 164 | void RenderWidgetHostView::FocusedNodeChanged(bool is_editable_node) { | 156 | void RenderWidgetHostView::FocusedNodeChanged(bool is_editable_node) { |
2166 | 165 | focused_node_is_editable_ = is_editable_node; | 157 | ime_bridge_.FocusedNodeChanged(is_editable_node); |
2163 | 166 | if (delegate_) { | ||
2164 | 167 | delegate_->FocusedNodeChanged(is_editable_node); | ||
2165 | 168 | } | ||
2167 | 169 | } | 158 | } |
2168 | 170 | 159 | ||
2169 | 171 | void RenderWidgetHostView::OnSwapCompositorFrame( | 160 | void RenderWidgetHostView::OnSwapCompositorFrame( |
2170 | @@ -186,9 +175,6 @@ | |||
2171 | 186 | return; | 175 | return; |
2172 | 187 | } | 176 | } |
2173 | 188 | 177 | ||
2174 | 189 | Compositor* compositor = delegate_ ? delegate_->GetCompositor() : nullptr; | ||
2175 | 190 | CompositorLock lock(compositor); | ||
2176 | 191 | |||
2177 | 192 | if (output_surface_id != last_output_surface_id_) { | 178 | if (output_surface_id != last_output_surface_id_) { |
2178 | 193 | resource_collection_->SetClient(nullptr); | 179 | resource_collection_->SetClient(nullptr); |
2179 | 194 | if (resource_collection_->LoseAllResources()) { | 180 | if (resource_collection_->LoseAllResources()) { |
2180 | @@ -228,10 +214,16 @@ | |||
2181 | 228 | frame_size != frame_provider_->frame_size() || | 214 | frame_size != frame_provider_->frame_size() || |
2182 | 229 | frame_size_dip != last_frame_size_dip_) { | 215 | frame_size_dip != last_frame_size_dip_) { |
2183 | 230 | DetachLayer(); | 216 | DetachLayer(); |
2184 | 217 | |||
2185 | 231 | frame_provider_ = new cc::DelegatedFrameProvider(resource_collection_, | 218 | frame_provider_ = new cc::DelegatedFrameProvider(resource_collection_, |
2186 | 232 | frame_data.Pass()); | 219 | frame_data.Pass()); |
2187 | 233 | layer_ = cc::DelegatedRendererLayer::Create(cc::LayerSettings(), | 220 | layer_ = cc::DelegatedRendererLayer::Create(cc::LayerSettings(), |
2188 | 234 | frame_provider_); | 221 | frame_provider_); |
2189 | 222 | layer_->SetIsDrawable(true); | ||
2190 | 223 | layer_->SetContentsOpaque(true); | ||
2191 | 224 | layer_->SetBounds(frame_size_dip); | ||
2192 | 225 | layer_->SetHideLayerAndSubtree(!is_showing_); | ||
2193 | 226 | |||
2194 | 235 | AttachLayer(); | 227 | AttachLayer(); |
2195 | 236 | } else { | 228 | } else { |
2196 | 237 | frame_provider_->SetFrameData(frame_data.Pass()); | 229 | frame_provider_->SetFrameData(frame_data.Pass()); |
2197 | @@ -241,15 +233,12 @@ | |||
2198 | 241 | last_frame_size_dip_ = frame_size_dip; | 233 | last_frame_size_dip_ = frame_size_dip; |
2199 | 242 | 234 | ||
2200 | 243 | if (layer_.get()) { | 235 | if (layer_.get()) { |
2201 | 244 | layer_->SetIsDrawable(true); | ||
2202 | 245 | layer_->SetContentsOpaque(true); | ||
2203 | 246 | layer_->SetBounds(frame_size_dip); | ||
2204 | 247 | layer_->SetNeedsDisplayRect(damage_rect_dip); | 236 | layer_->SetNeedsDisplayRect(damage_rect_dip); |
2205 | 248 | } | 237 | } |
2206 | 249 | 238 | ||
2207 | 250 | if (frame_is_evicted_) { | 239 | if (frame_is_evicted_) { |
2208 | 251 | frame_is_evicted_ = false; | 240 | frame_is_evicted_ = false; |
2210 | 252 | RendererFrameEvictor::GetInstance()->AddFrame(this, IsShowing()); | 241 | RendererFrameEvictor::GetInstance()->AddFrame(this, is_showing_); |
2211 | 253 | } | 242 | } |
2212 | 254 | 243 | ||
2213 | 255 | compositor_frame_metadata_ = frame->metadata; | 244 | compositor_frame_metadata_ = frame->metadata; |
2214 | @@ -267,6 +256,7 @@ | |||
2215 | 267 | gesture_provider_->SetDoubleTapSupportForPageEnabled( | 256 | gesture_provider_->SetDoubleTapSupportForPageEnabled( |
2216 | 268 | !has_fixed_page_scale && !has_mobile_viewport); | 257 | !has_fixed_page_scale && !has_mobile_viewport); |
2217 | 269 | 258 | ||
2218 | 259 | Compositor* compositor = container_->GetCompositor(); | ||
2219 | 270 | if (!compositor || !compositor->IsActive()) { | 260 | if (!compositor || !compositor->IsActive()) { |
2220 | 271 | RunAckCallbacks(); | 261 | RunAckCallbacks(); |
2221 | 272 | } | 262 | } |
2222 | @@ -291,12 +281,17 @@ | |||
2223 | 291 | const std::vector<content::WebPluginGeometry>& moves) {} | 281 | const std::vector<content::WebPluginGeometry>& moves) {} |
2224 | 292 | 282 | ||
2225 | 293 | void RenderWidgetHostView::UpdateCursor(const content::WebCursor& cursor) { | 283 | void RenderWidgetHostView::UpdateCursor(const content::WebCursor& cursor) { |
2232 | 294 | if (cursor.IsEqual(current_cursor_)) { | 284 | if (cursor.IsEqual(web_cursor_)) { |
2233 | 295 | return; | 285 | return; |
2234 | 296 | } | 286 | } |
2235 | 297 | 287 | ||
2236 | 298 | current_cursor_ = cursor; | 288 | web_cursor_ = cursor; |
2237 | 299 | UpdateCursorOnWebView(); | 289 | |
2238 | 290 | if (is_loading_) { | ||
2239 | 291 | return; | ||
2240 | 292 | } | ||
2241 | 293 | |||
2242 | 294 | UpdateCurrentCursor(); | ||
2243 | 300 | } | 295 | } |
2244 | 301 | 296 | ||
2245 | 302 | void RenderWidgetHostView::SetIsLoading(bool is_loading) { | 297 | void RenderWidgetHostView::SetIsLoading(bool is_loading) { |
2246 | @@ -305,15 +300,15 @@ | |||
2247 | 305 | } | 300 | } |
2248 | 306 | 301 | ||
2249 | 307 | is_loading_ = is_loading; | 302 | is_loading_ = is_loading; |
2251 | 308 | UpdateCursorOnWebView(); | 303 | UpdateCurrentCursor(); |
2252 | 309 | } | 304 | } |
2253 | 310 | 305 | ||
2254 | 311 | void RenderWidgetHostView::ImeCancelComposition() { | 306 | void RenderWidgetHostView::ImeCancelComposition() { |
2256 | 312 | if (!delegate_) { | 307 | if (!ime_bridge_.context()) { |
2257 | 313 | return; | 308 | return; |
2258 | 314 | } | 309 | } |
2259 | 315 | 310 | ||
2261 | 316 | delegate_->ImeCancelComposition(); | 311 | ime_bridge_.context()->CancelComposition(); |
2262 | 317 | } | 312 | } |
2263 | 318 | 313 | ||
2264 | 319 | void RenderWidgetHostView::RenderProcessGone(base::TerminationStatus status, | 314 | void RenderWidgetHostView::RenderProcessGone(base::TerminationStatus status, |
2265 | @@ -354,13 +349,13 @@ | |||
2266 | 354 | } | 349 | } |
2267 | 355 | 350 | ||
2268 | 356 | void RenderWidgetHostView::GetScreenInfo(blink::WebScreenInfo* result) { | 351 | void RenderWidgetHostView::GetScreenInfo(blink::WebScreenInfo* result) { |
2270 | 357 | if (!delegate_) { | 352 | if (!container_) { |
2271 | 358 | *result = | 353 | *result = |
2272 | 359 | BrowserPlatformIntegration::GetInstance()->GetDefaultScreenInfo(); | 354 | BrowserPlatformIntegration::GetInstance()->GetDefaultScreenInfo(); |
2273 | 360 | return; | 355 | return; |
2274 | 361 | } | 356 | } |
2275 | 362 | 357 | ||
2277 | 363 | *result = delegate_->GetScreenInfo(); | 358 | *result = container_->GetScreenInfo(); |
2278 | 364 | } | 359 | } |
2279 | 365 | 360 | ||
2280 | 366 | bool RenderWidgetHostView::GetScreenColorProfile( | 361 | bool RenderWidgetHostView::GetScreenColorProfile( |
2281 | @@ -412,11 +407,11 @@ | |||
2282 | 412 | } | 407 | } |
2283 | 413 | 408 | ||
2284 | 414 | bool RenderWidgetHostView::HasFocus() const { | 409 | bool RenderWidgetHostView::HasFocus() const { |
2286 | 415 | if (!delegate_) { | 410 | if (!container_) { |
2287 | 416 | return false; | 411 | return false; |
2288 | 417 | } | 412 | } |
2289 | 418 | 413 | ||
2291 | 419 | return delegate_->HasFocus(); | 414 | return container_->HasFocus(this); |
2292 | 420 | } | 415 | } |
2293 | 421 | 416 | ||
2294 | 422 | bool RenderWidgetHostView::IsSurfaceAvailableForCopy() const { | 417 | bool RenderWidgetHostView::IsSurfaceAvailableForCopy() const { |
2295 | @@ -425,20 +420,22 @@ | |||
2296 | 425 | 420 | ||
2297 | 426 | void RenderWidgetHostView::Show() { | 421 | void RenderWidgetHostView::Show() { |
2298 | 427 | if (is_showing_) { | 422 | if (is_showing_) { |
2307 | 428 | DCHECK(delegate_); | 423 | return; |
2308 | 429 | return; | 424 | } |
2301 | 430 | } | ||
2302 | 431 | |||
2303 | 432 | if (!delegate_) { | ||
2304 | 433 | return; | ||
2305 | 434 | } | ||
2306 | 435 | |||
2309 | 436 | is_showing_ = true; | 425 | is_showing_ = true; |
2310 | 437 | 426 | ||
2311 | 427 | if (layer_.get()) { | ||
2312 | 428 | layer_->SetHideLayerAndSubtree(false); | ||
2313 | 429 | } | ||
2314 | 430 | |||
2315 | 438 | if (!frame_is_evicted_) { | 431 | if (!frame_is_evicted_) { |
2316 | 439 | RendererFrameEvictor::GetInstance()->LockFrame(this); | 432 | RendererFrameEvictor::GetInstance()->LockFrame(this); |
2317 | 440 | } | 433 | } |
2318 | 441 | 434 | ||
2319 | 435 | if (!host_ || !host_->is_hidden()) { | ||
2320 | 436 | return; | ||
2321 | 437 | } | ||
2322 | 438 | |||
2323 | 442 | host_->WasShown(ui::LatencyInfo()); | 439 | host_->WasShown(ui::LatencyInfo()); |
2324 | 443 | } | 440 | } |
2325 | 444 | 441 | ||
2326 | @@ -446,30 +443,36 @@ | |||
2327 | 446 | if (!is_showing_) { | 443 | if (!is_showing_) { |
2328 | 447 | return; | 444 | return; |
2329 | 448 | } | 445 | } |
2330 | 449 | |||
2331 | 450 | is_showing_ = false; | 446 | is_showing_ = false; |
2332 | 451 | 447 | ||
2333 | 448 | if (layer_.get()) { | ||
2334 | 449 | layer_->SetHideLayerAndSubtree(true); | ||
2335 | 450 | } | ||
2336 | 451 | |||
2337 | 452 | if (!frame_is_evicted_) { | 452 | if (!frame_is_evicted_) { |
2338 | 453 | RendererFrameEvictor::GetInstance()->UnlockFrame(this); | 453 | RendererFrameEvictor::GetInstance()->UnlockFrame(this); |
2339 | 454 | } | 454 | } |
2340 | 455 | 455 | ||
2341 | 456 | RunAckCallbacks(); | ||
2342 | 457 | |||
2343 | 458 | if (!host_ || host_->is_hidden()) { | ||
2344 | 459 | return; | ||
2345 | 460 | } | ||
2346 | 461 | |||
2347 | 456 | host_->WasHidden(); | 462 | host_->WasHidden(); |
2348 | 457 | |||
2349 | 458 | RunAckCallbacks(); | ||
2350 | 459 | } | 463 | } |
2351 | 460 | 464 | ||
2352 | 461 | bool RenderWidgetHostView::IsShowing() { | 465 | bool RenderWidgetHostView::IsShowing() { |
2355 | 462 | DCHECK(!is_showing_ || delegate_); | 466 | return is_showing_ && container_ && container_->IsVisible(); |
2354 | 463 | return is_showing_; | ||
2356 | 464 | } | 467 | } |
2357 | 465 | 468 | ||
2358 | 466 | gfx::Rect RenderWidgetHostView::GetViewBounds() const { | 469 | gfx::Rect RenderWidgetHostView::GetViewBounds() const { |
2359 | 467 | gfx::Rect bounds; | 470 | gfx::Rect bounds; |
2360 | 468 | 471 | ||
2362 | 469 | if (!delegate_) { | 472 | if (!container_) { |
2363 | 470 | bounds = gfx::Rect(last_size_); | 473 | bounds = gfx::Rect(last_size_); |
2364 | 471 | } else { | 474 | } else { |
2366 | 472 | bounds = delegate_->GetViewBoundsDip(); | 475 | bounds = container_->GetViewBoundsDip(); |
2367 | 473 | } | 476 | } |
2368 | 474 | 477 | ||
2369 | 475 | if (DoTopControlsShrinkBlinkSize()) { | 478 | if (DoTopControlsShrinkBlinkSize()) { |
2370 | @@ -485,6 +488,10 @@ | |||
2371 | 485 | 488 | ||
2372 | 486 | void RenderWidgetHostView::UnlockMouse() {} | 489 | void RenderWidgetHostView::UnlockMouse() {} |
2373 | 487 | 490 | ||
2374 | 491 | void RenderWidgetHostView::CompositorDidCommit() { | ||
2375 | 492 | RunAckCallbacks(); | ||
2376 | 493 | } | ||
2377 | 494 | |||
2378 | 488 | void RenderWidgetHostView::OnGestureEvent( | 495 | void RenderWidgetHostView::OnGestureEvent( |
2379 | 489 | const blink::WebGestureEvent& event) { | 496 | const blink::WebGestureEvent& event) { |
2380 | 490 | if (!host_) { | 497 | if (!host_) { |
2381 | @@ -517,10 +524,6 @@ | |||
2382 | 517 | void RenderWidgetHostView::EvictCurrentFrame() { | 524 | void RenderWidgetHostView::EvictCurrentFrame() { |
2383 | 518 | frame_is_evicted_ = true; | 525 | frame_is_evicted_ = true; |
2384 | 519 | DestroyDelegatedContent(); | 526 | DestroyDelegatedContent(); |
2385 | 520 | |||
2386 | 521 | if (delegate_) { | ||
2387 | 522 | delegate_->EvictCurrentFrame(); | ||
2388 | 523 | } | ||
2389 | 524 | } | 527 | } |
2390 | 525 | 528 | ||
2391 | 526 | void RenderWidgetHostView::UnusedResourcesAreAvailable() { | 529 | void RenderWidgetHostView::UnusedResourcesAreAvailable() { |
2392 | @@ -529,19 +532,20 @@ | |||
2393 | 529 | } | 532 | } |
2394 | 530 | } | 533 | } |
2395 | 531 | 534 | ||
2401 | 532 | void RenderWidgetHostView::UpdateCursorOnWebView() { | 535 | void RenderWidgetHostView::UpdateCurrentCursor() { |
2397 | 533 | if (!delegate_) { | ||
2398 | 534 | return; | ||
2399 | 535 | } | ||
2400 | 536 | |||
2402 | 537 | if (is_loading_) { | 536 | if (is_loading_) { |
2403 | 538 | content::WebCursor::CursorInfo busy_cursor_info( | 537 | content::WebCursor::CursorInfo busy_cursor_info( |
2404 | 539 | blink::WebCursorInfo::TypeWait); | 538 | blink::WebCursorInfo::TypeWait); |
2407 | 540 | content::WebCursor busy_cursor(busy_cursor_info); | 539 | current_cursor_ = content::WebCursor(busy_cursor_info); |
2406 | 541 | delegate_->UpdateCursor(busy_cursor); | ||
2408 | 542 | } else { | 540 | } else { |
2411 | 543 | delegate_->UpdateCursor(current_cursor_); | 541 | current_cursor_ = web_cursor_; |
2412 | 544 | } | 542 | } |
2413 | 543 | |||
2414 | 544 | if (!container_) { | ||
2415 | 545 | return; | ||
2416 | 546 | } | ||
2417 | 547 | |||
2418 | 548 | container_->CursorChanged(); | ||
2419 | 545 | } | 549 | } |
2420 | 546 | 550 | ||
2421 | 547 | void RenderWidgetHostView::DestroyDelegatedContent() { | 551 | void RenderWidgetHostView::DestroyDelegatedContent() { |
2422 | @@ -582,92 +586,76 @@ | |||
2423 | 582 | } | 586 | } |
2424 | 583 | 587 | ||
2425 | 584 | void RenderWidgetHostView::AttachLayer() { | 588 | void RenderWidgetHostView::AttachLayer() { |
2427 | 585 | if (!delegate_) { | 589 | if (!container_) { |
2428 | 586 | return; | 590 | return; |
2429 | 587 | } | 591 | } |
2430 | 588 | if (!layer_.get()) { | 592 | if (!layer_.get()) { |
2431 | 589 | return; | 593 | return; |
2432 | 590 | } | 594 | } |
2433 | 591 | 595 | ||
2435 | 592 | delegate_->GetCompositor()->SetRootLayer(layer_.get()); | 596 | container_->AttachLayer(layer_); |
2436 | 593 | } | 597 | } |
2437 | 594 | 598 | ||
2438 | 595 | void RenderWidgetHostView::DetachLayer() { | 599 | void RenderWidgetHostView::DetachLayer() { |
2440 | 596 | if (!delegate_) { | 600 | if (!container_) { |
2441 | 597 | return; | 601 | return; |
2442 | 598 | } | 602 | } |
2443 | 599 | if (!layer_.get()) { | 603 | if (!layer_.get()) { |
2444 | 600 | return; | 604 | return; |
2445 | 601 | } | 605 | } |
2446 | 602 | 606 | ||
2448 | 603 | delegate_->GetCompositor()->SetRootLayer(scoped_refptr<cc::Layer>()); | 607 | container_->DetachLayer(layer_); |
2449 | 604 | } | 608 | } |
2450 | 605 | 609 | ||
2466 | 606 | RenderWidgetHostView::RenderWidgetHostView(content::RenderWidgetHost* host) : | 610 | RenderWidgetHostView::RenderWidgetHostView( |
2467 | 607 | host_(content::RenderWidgetHostImpl::From(host)), | 611 | content::RenderWidgetHost* host, |
2468 | 608 | delegate_(nullptr), | 612 | RenderWidgetHostViewContainer* container) |
2469 | 609 | resource_collection_(new cc::DelegatedFrameResourceCollection()), | 613 | : host_(content::RenderWidgetHostImpl::From(host)), |
2470 | 610 | last_output_surface_id_(0), | 614 | container_(container), |
2471 | 611 | frame_is_evicted_(true), | 615 | resource_collection_(new cc::DelegatedFrameResourceCollection()), |
2472 | 612 | selection_cursor_position_(0), | 616 | last_output_surface_id_(0), |
2473 | 613 | selection_anchor_position_(0), | 617 | frame_is_evicted_(true), |
2474 | 614 | current_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 618 | ime_bridge_(this), |
2475 | 615 | show_ime_if_needed_(false), | 619 | is_loading_(false), |
2476 | 616 | focused_node_is_editable_(false), | 620 | is_showing_(false), |
2477 | 617 | is_loading_(false), | 621 | top_controls_shrink_blink_size_(false), |
2478 | 618 | is_showing_(false), | 622 | gesture_provider_(GestureProvider::Create(this)) { |
2464 | 619 | top_controls_shrink_blink_size_(false), | ||
2465 | 620 | gesture_provider_(GestureProvider::Create(this)) { | ||
2479 | 621 | CHECK(host_) << "Implementation didn't supply a RenderWidgetHost"; | 623 | CHECK(host_) << "Implementation didn't supply a RenderWidgetHost"; |
2480 | 622 | 624 | ||
2481 | 623 | resource_collection_->SetClient(this); | 625 | resource_collection_->SetClient(this); |
2482 | 624 | host_->SetView(this); | 626 | host_->SetView(this); |
2483 | 625 | 627 | ||
2484 | 626 | gesture_provider_->SetDoubleTapSupportForPageEnabled(false); | 628 | gesture_provider_->SetDoubleTapSupportForPageEnabled(false); |
2485 | 629 | |||
2486 | 630 | if (container) { | ||
2487 | 631 | CompositorObserver::Observe(container->GetCompositor()); | ||
2488 | 632 | } | ||
2489 | 627 | } | 633 | } |
2490 | 628 | 634 | ||
2491 | 629 | RenderWidgetHostView::~RenderWidgetHostView() { | 635 | RenderWidgetHostView::~RenderWidgetHostView() { |
2492 | 630 | resource_collection_->SetClient(nullptr); | 636 | resource_collection_->SetClient(nullptr); |
2503 | 631 | SetDelegate(nullptr); | 637 | SetContainer(nullptr); |
2504 | 632 | } | 638 | } |
2505 | 633 | 639 | ||
2506 | 634 | void RenderWidgetHostView::CompositorDidCommit() { | 640 | void RenderWidgetHostView::SetContainer( |
2507 | 635 | RunAckCallbacks(); | 641 | RenderWidgetHostViewContainer* container) { |
2508 | 636 | } | 642 | if (container == container_) { |
2499 | 637 | |||
2500 | 638 | void RenderWidgetHostView::SetDelegate( | ||
2501 | 639 | RenderWidgetHostViewDelegate* delegate) { | ||
2502 | 640 | if (delegate == delegate_) { | ||
2509 | 641 | return; | 643 | return; |
2510 | 642 | } | 644 | } |
2511 | 643 | 645 | ||
2512 | 644 | DetachLayer(); | 646 | DetachLayer(); |
2514 | 645 | delegate_ = delegate; | 647 | container_ = container; |
2515 | 646 | AttachLayer(); | 648 | AttachLayer(); |
2516 | 647 | 649 | ||
2539 | 648 | if (delegate_) { | 650 | CompositorObserver::Observe( |
2540 | 649 | DCHECK(host_) << | 651 | container_ ? container_->GetCompositor() : nullptr); |
2541 | 650 | "Shouldn't be attaching to a delegate when we're already destroyed"; | 652 | |
2542 | 651 | host_->SendScreenRects(); | 653 | if (!host_) { |
2543 | 652 | host_->WasResized(); | 654 | return; |
2522 | 653 | |||
2523 | 654 | if (delegate_->IsVisible()) { | ||
2524 | 655 | Show(); | ||
2525 | 656 | } else { | ||
2526 | 657 | Hide(); | ||
2527 | 658 | } | ||
2528 | 659 | |||
2529 | 660 | UpdateCursorOnWebView(); | ||
2530 | 661 | delegate_->TextInputStateChanged(current_text_input_type_, | ||
2531 | 662 | show_ime_if_needed_); | ||
2532 | 663 | delegate_->FocusedNodeChanged(focused_node_is_editable_); | ||
2533 | 664 | delegate_->SelectionBoundsChanged(caret_rect_, | ||
2534 | 665 | selection_cursor_position_, | ||
2535 | 666 | selection_anchor_position_); | ||
2536 | 667 | delegate_->SelectionChanged(); | ||
2537 | 668 | } else if (host_) { | ||
2538 | 669 | Hide(); | ||
2544 | 670 | } | 655 | } |
2545 | 656 | |||
2546 | 657 | host_->SendScreenRects(); | ||
2547 | 658 | host_->WasResized(); | ||
2548 | 671 | } | 659 | } |
2549 | 672 | 660 | ||
2550 | 673 | void RenderWidgetHostView::Blur() { | 661 | void RenderWidgetHostView::Blur() { |
2551 | 674 | 662 | ||
2552 | === modified file 'shared/browser/oxide_render_widget_host_view.h' | |||
2553 | --- shared/browser/oxide_render_widget_host_view.h 2015-09-29 08:25:11 +0000 | |||
2554 | +++ shared/browser/oxide_render_widget_host_view.h 2015-10-21 17:31:00 +0000 | |||
2555 | @@ -30,10 +30,10 @@ | |||
2556 | 30 | #include "cc/layers/delegated_frame_resource_collection.h" | 30 | #include "cc/layers/delegated_frame_resource_collection.h" |
2557 | 31 | #include "cc/output/compositor_frame_metadata.h" | 31 | #include "cc/output/compositor_frame_metadata.h" |
2558 | 32 | #include "content/common/cursors/webcursor.h" | 32 | #include "content/common/cursors/webcursor.h" |
2559 | 33 | #include "ui/base/ime/text_input_type.h" | ||
2560 | 34 | #include "ui/gfx/geometry/rect.h" | ||
2561 | 35 | #include "ui/gfx/geometry/size.h" | 33 | #include "ui/gfx/geometry/size.h" |
2562 | 36 | 34 | ||
2563 | 35 | #include "shared/browser/compositor/oxide_compositor_observer.h" | ||
2564 | 36 | #include "shared/browser/input/oxide_ime_bridge_impl.h" | ||
2565 | 37 | #include "shared/browser/oxide_gesture_provider.h" | 37 | #include "shared/browser/oxide_gesture_provider.h" |
2566 | 38 | #include "shared/browser/oxide_renderer_frame_evictor_client.h" | 38 | #include "shared/browser/oxide_renderer_frame_evictor_client.h" |
2567 | 39 | #include "shared/port/content/browser/render_widget_host_view_oxide.h" | 39 | #include "shared/port/content/browser/render_widget_host_view_oxide.h" |
2568 | @@ -53,23 +53,25 @@ | |||
2569 | 53 | 53 | ||
2570 | 54 | namespace oxide { | 54 | namespace oxide { |
2571 | 55 | 55 | ||
2574 | 56 | class RenderWidgetHostViewDelegate; | 56 | class RenderWidgetHostViewContainer; |
2573 | 57 | class WebView; | ||
2575 | 58 | 57 | ||
2576 | 59 | class RenderWidgetHostView final : | 58 | class RenderWidgetHostView final : |
2577 | 60 | public content::RenderWidgetHostViewOxide, | 59 | public content::RenderWidgetHostViewOxide, |
2578 | 60 | public CompositorObserver, | ||
2579 | 61 | public GestureProviderClient, | 61 | public GestureProviderClient, |
2580 | 62 | public RendererFrameEvictorClient, | 62 | public RendererFrameEvictorClient, |
2581 | 63 | public cc::DelegatedFrameResourceCollectionClient, | 63 | public cc::DelegatedFrameResourceCollectionClient, |
2582 | 64 | public base::SupportsWeakPtr<RenderWidgetHostView> { | 64 | public base::SupportsWeakPtr<RenderWidgetHostView> { |
2583 | 65 | public: | 65 | public: |
2585 | 66 | RenderWidgetHostView(content::RenderWidgetHost* render_widget_host); | 66 | RenderWidgetHostView(content::RenderWidgetHost* render_widget_host, |
2586 | 67 | RenderWidgetHostViewContainer* container); | ||
2587 | 67 | ~RenderWidgetHostView(); | 68 | ~RenderWidgetHostView(); |
2588 | 68 | 69 | ||
2589 | 69 | content::RenderWidgetHostImpl* host() const { return host_; } | 70 | content::RenderWidgetHostImpl* host() const { return host_; } |
2590 | 70 | 71 | ||
2593 | 71 | void CompositorDidCommit(); | 72 | void SetContainer(RenderWidgetHostViewContainer* container); |
2594 | 72 | void SetDelegate(RenderWidgetHostViewDelegate* delegate); | 73 | |
2595 | 74 | ImeBridgeImpl* ime_bridge() { return &ime_bridge_; } | ||
2596 | 73 | 75 | ||
2597 | 74 | const base::string16& selection_text() const { | 76 | const base::string16& selection_text() const { |
2598 | 75 | return selection_text_; | 77 | return selection_text_; |
2599 | @@ -79,6 +81,8 @@ | |||
2600 | 79 | return compositor_frame_metadata_; | 81 | return compositor_frame_metadata_; |
2601 | 80 | } | 82 | } |
2602 | 81 | 83 | ||
2603 | 84 | const content::WebCursor& current_cursor() const { return current_cursor_; } | ||
2604 | 85 | |||
2605 | 82 | void HandleTouchEvent(const ui::MotionEvent& event); | 86 | void HandleTouchEvent(const ui::MotionEvent& event); |
2606 | 83 | void ResetGestureDetection(); | 87 | void ResetGestureDetection(); |
2607 | 84 | 88 | ||
2608 | @@ -158,6 +162,9 @@ | |||
2609 | 158 | bool LockMouse() final; | 162 | bool LockMouse() final; |
2610 | 159 | void UnlockMouse() final; | 163 | void UnlockMouse() final; |
2611 | 160 | 164 | ||
2612 | 165 | // CompositorObserver implementation | ||
2613 | 166 | void CompositorDidCommit() final; | ||
2614 | 167 | |||
2615 | 161 | // GestureProviderClient implementation | 168 | // GestureProviderClient implementation |
2616 | 162 | void OnGestureEvent(const blink::WebGestureEvent& event) final; | 169 | void OnGestureEvent(const blink::WebGestureEvent& event) final; |
2617 | 163 | 170 | ||
2618 | @@ -169,7 +176,7 @@ | |||
2619 | 169 | 176 | ||
2620 | 170 | // =================== | 177 | // =================== |
2621 | 171 | 178 | ||
2623 | 172 | void UpdateCursorOnWebView(); | 179 | void UpdateCurrentCursor(); |
2624 | 173 | 180 | ||
2625 | 174 | void DestroyDelegatedContent(); | 181 | void DestroyDelegatedContent(); |
2626 | 175 | void SendDelegatedFrameAck(uint32 surface_id); | 182 | void SendDelegatedFrameAck(uint32 surface_id); |
2627 | @@ -180,7 +187,7 @@ | |||
2628 | 180 | 187 | ||
2629 | 181 | content::RenderWidgetHostImpl* host_; | 188 | content::RenderWidgetHostImpl* host_; |
2630 | 182 | 189 | ||
2632 | 183 | RenderWidgetHostViewDelegate* delegate_; | 190 | RenderWidgetHostViewContainer* container_; |
2633 | 184 | 191 | ||
2634 | 185 | gfx::GLSurfaceHandle shared_surface_handle_; | 192 | gfx::GLSurfaceHandle shared_surface_handle_; |
2635 | 186 | 193 | ||
2636 | @@ -197,15 +204,10 @@ | |||
2637 | 197 | 204 | ||
2638 | 198 | bool frame_is_evicted_; | 205 | bool frame_is_evicted_; |
2639 | 199 | 206 | ||
2647 | 200 | gfx::Rect caret_rect_; | 207 | ImeBridgeImpl ime_bridge_; |
2641 | 201 | size_t selection_cursor_position_; | ||
2642 | 202 | size_t selection_anchor_position_; | ||
2643 | 203 | |||
2644 | 204 | ui::TextInputType current_text_input_type_; | ||
2645 | 205 | bool show_ime_if_needed_; | ||
2646 | 206 | bool focused_node_is_editable_; | ||
2648 | 207 | 208 | ||
2649 | 208 | bool is_loading_; | 209 | bool is_loading_; |
2650 | 210 | content::WebCursor web_cursor_; | ||
2651 | 209 | content::WebCursor current_cursor_; | 211 | content::WebCursor current_cursor_; |
2652 | 210 | 212 | ||
2653 | 211 | bool is_showing_; | 213 | bool is_showing_; |
2654 | 212 | 214 | ||
2655 | === renamed file 'shared/browser/oxide_render_widget_host_view_delegate.h' => 'shared/browser/oxide_render_widget_host_view_container.h' | |||
2656 | --- shared/browser/oxide_render_widget_host_view_delegate.h 2015-05-14 15:37:57 +0000 | |||
2657 | +++ shared/browser/oxide_render_widget_host_view_container.h 2015-10-21 17:31:00 +0000 | |||
2658 | @@ -1,5 +1,5 @@ | |||
2659 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: |
2661 | 2 | // Copyright (C) 2014 Canonical Ltd. | 2 | // Copyright (C) 2014-2015 Canonical Ltd. |
2662 | 3 | 3 | ||
2663 | 4 | // This library is free software; you can redistribute it and/or | 4 | // This library is free software; you can redistribute it and/or |
2664 | 5 | // modify it under the terms of the GNU Lesser General Public | 5 | // modify it under the terms of the GNU Lesser General Public |
2665 | @@ -15,16 +15,24 @@ | |||
2666 | 15 | // License along with this library; if not, write to the Free Software | 15 | // License along with this library; if not, write to the Free Software |
2667 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2668 | 17 | 17 | ||
2672 | 18 | #ifndef _OXIDE_SHARED_BROWSER_RENDER_WIDGET_HOST_VIEW_DELEGATE_H_ | 18 | #ifndef _OXIDE_SHARED_BROWSER_RENDER_WIDGET_HOST_VIEW_CONTAINER_H_ |
2673 | 19 | #define _OXIDE_SHARED_BROWSER_RENDER_WIDGET_HOST_VIEW_DELEGATE_H_ | 19 | #define _OXIDE_SHARED_BROWSER_RENDER_WIDGET_HOST_VIEW_CONTAINER_H_ |
2674 | 20 | 20 | ||
2675 | 21 | #include <vector> | ||
2676 | 22 | |||
2677 | 23 | #include "base/memory/ref_counted.h" | ||
2678 | 24 | #include "content/public/common/menu_item.h" | ||
2679 | 21 | #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 25 | #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
2680 | 22 | #include "ui/base/ime/text_input_type.h" | ||
2681 | 23 | #include "ui/gfx/geometry/rect.h" | 26 | #include "ui/gfx/geometry/rect.h" |
2682 | 24 | #include "ui/gfx/geometry/size.h" | 27 | #include "ui/gfx/geometry/size.h" |
2683 | 25 | 28 | ||
2684 | 29 | namespace cc { | ||
2685 | 30 | class Layer; | ||
2686 | 31 | } | ||
2687 | 32 | |||
2688 | 26 | namespace content { | 33 | namespace content { |
2690 | 27 | class WebCursor; | 34 | struct ContextMenuParams; |
2691 | 35 | class RenderFrameHost; | ||
2692 | 28 | } | 36 | } |
2693 | 29 | 37 | ||
2694 | 30 | namespace gfx { | 38 | namespace gfx { |
2695 | @@ -34,44 +42,43 @@ | |||
2696 | 34 | namespace oxide { | 42 | namespace oxide { |
2697 | 35 | 43 | ||
2698 | 36 | class Compositor; | 44 | class Compositor; |
2700 | 37 | class WebView; | 45 | class RenderWidgetHostView; |
2701 | 38 | 46 | ||
2703 | 39 | class RenderWidgetHostViewDelegate { | 47 | class RenderWidgetHostViewContainer { |
2704 | 40 | public: | 48 | public: |
2723 | 41 | virtual ~RenderWidgetHostViewDelegate() {} | 49 | virtual ~RenderWidgetHostViewContainer() {} |
2706 | 42 | |||
2707 | 43 | virtual void EvictCurrentFrame() = 0; | ||
2708 | 44 | |||
2709 | 45 | virtual void UpdateCursor(const content::WebCursor& cursor) = 0; | ||
2710 | 46 | |||
2711 | 47 | virtual void TextInputStateChanged(ui::TextInputType type, | ||
2712 | 48 | bool show_ime_if_needed) = 0; | ||
2713 | 49 | |||
2714 | 50 | virtual void FocusedNodeChanged(bool is_editable_node) = 0; | ||
2715 | 51 | |||
2716 | 52 | virtual void ImeCancelComposition() = 0; | ||
2717 | 53 | |||
2718 | 54 | virtual void SelectionBoundsChanged(const gfx::Rect& caret_rect, | ||
2719 | 55 | size_t selection_cursor_position, | ||
2720 | 56 | size_t selection_anchor_position) = 0; | ||
2721 | 57 | |||
2722 | 58 | virtual void SelectionChanged() = 0; | ||
2724 | 59 | 50 | ||
2725 | 60 | virtual Compositor* GetCompositor() const = 0; | 51 | virtual Compositor* GetCompositor() const = 0; |
2726 | 61 | 52 | ||
2727 | 53 | virtual void AttachLayer(scoped_refptr<cc::Layer> layer) = 0; | ||
2728 | 54 | |||
2729 | 55 | virtual void DetachLayer(scoped_refptr<cc::Layer> layer) = 0; | ||
2730 | 56 | |||
2731 | 57 | virtual void CursorChanged() = 0; | ||
2732 | 58 | |||
2733 | 62 | virtual gfx::Size GetViewSizePix() const = 0; | 59 | virtual gfx::Size GetViewSizePix() const = 0; |
2734 | 63 | 60 | ||
2735 | 64 | virtual gfx::Rect GetViewBoundsDip() const = 0; | 61 | virtual gfx::Rect GetViewBoundsDip() const = 0; |
2736 | 65 | 62 | ||
2737 | 66 | virtual blink::WebScreenInfo GetScreenInfo() const = 0; | 63 | virtual blink::WebScreenInfo GetScreenInfo() const = 0; |
2738 | 67 | 64 | ||
2740 | 68 | virtual bool HasFocus() const = 0; | 65 | virtual bool HasFocus(const RenderWidgetHostView* view) const = 0; |
2741 | 69 | 66 | ||
2742 | 70 | virtual bool IsVisible() const = 0; | 67 | virtual bool IsVisible() const = 0; |
2743 | 71 | 68 | ||
2744 | 72 | virtual float GetLocationBarHeightDip() const = 0; | 69 | virtual float GetLocationBarHeightDip() const = 0; |
2745 | 70 | |||
2746 | 71 | virtual void ShowContextMenu(content::RenderFrameHost* render_frame_host, | ||
2747 | 72 | const content::ContextMenuParams& params) = 0; | ||
2748 | 73 | |||
2749 | 74 | virtual void ShowPopupMenu(content::RenderFrameHost* render_frame_host, | ||
2750 | 75 | const gfx::Rect& bounds, | ||
2751 | 76 | int selected_item, | ||
2752 | 77 | const std::vector<content::MenuItem>& items, | ||
2753 | 78 | bool allow_multiple_selection) = 0; | ||
2754 | 79 | virtual void HidePopupMenu() = 0; | ||
2755 | 73 | }; | 80 | }; |
2756 | 74 | 81 | ||
2757 | 75 | } // namespace oxide | 82 | } // namespace oxide |
2758 | 76 | 83 | ||
2760 | 77 | #endif // _OXIDE_SHARED_BROWSER_RENDER_WIDGET_HOST_VIEW_DELEGATE_H_ | 84 | #endif // _OXIDE_SHARED_BROWSER_RENDER_WIDGET_HOST_VIEW_CONTAINER_H_ |
2761 | 78 | 85 | ||
2762 | === modified file 'shared/browser/oxide_web_contents_view.cc' | |||
2763 | --- shared/browser/oxide_web_contents_view.cc 2015-05-28 23:51:39 +0000 | |||
2764 | +++ shared/browser/oxide_web_contents_view.cc 2015-10-21 17:31:00 +0000 | |||
2765 | @@ -21,15 +21,27 @@ | |||
2766 | 21 | #include "content/browser/web_contents/web_contents_impl.h" | 21 | #include "content/browser/web_contents/web_contents_impl.h" |
2767 | 22 | #include "content/public/browser/web_contents.h" | 22 | #include "content/public/browser/web_contents.h" |
2768 | 23 | 23 | ||
2769 | 24 | #include "shared/common/oxide_unowned_user_data.h" | ||
2770 | 25 | |||
2771 | 24 | #include "oxide_render_widget_host_view.h" | 26 | #include "oxide_render_widget_host_view.h" |
2773 | 25 | #include "oxide_web_view.h" | 27 | #include "oxide_render_widget_host_view_container.h" |
2774 | 26 | 28 | ||
2775 | 27 | namespace oxide { | 29 | namespace oxide { |
2776 | 28 | 30 | ||
2781 | 29 | WebContentsView::WebContentsView(content::WebContents* web_contents) : | 31 | namespace { |
2782 | 30 | web_contents_(web_contents) {} | 32 | int kUserDataKey; |
2783 | 31 | 33 | } | |
2784 | 32 | WebContentsView::~WebContentsView() {} | 34 | |
2785 | 35 | WebContentsView::WebContentsView(content::WebContents* web_contents) | ||
2786 | 36 | : web_contents_(web_contents), | ||
2787 | 37 | container_(nullptr) { | ||
2788 | 38 | web_contents_->SetUserData(&kUserDataKey, | ||
2789 | 39 | new UnownedUserData<WebContentsView>(this)); | ||
2790 | 40 | } | ||
2791 | 41 | |||
2792 | 42 | WebContentsView::~WebContentsView() { | ||
2793 | 43 | web_contents_->RemoveUserData(&kUserDataKey); | ||
2794 | 44 | } | ||
2795 | 33 | 45 | ||
2796 | 34 | // static | 46 | // static |
2797 | 35 | content::WebContentsViewOxide* WebContentsView::Create( | 47 | content::WebContentsViewOxide* WebContentsView::Create( |
2798 | @@ -37,8 +49,27 @@ | |||
2799 | 37 | return new WebContentsView(web_contents); | 49 | return new WebContentsView(web_contents); |
2800 | 38 | } | 50 | } |
2801 | 39 | 51 | ||
2804 | 40 | WebView* WebContentsView::GetWebView() const { | 52 | // static |
2805 | 41 | return WebView::FromWebContents(web_contents_); | 53 | WebContentsView* WebContentsView::FromWebContents( |
2806 | 54 | content::WebContents* contents) { | ||
2807 | 55 | UnownedUserData<WebContentsView>* data = | ||
2808 | 56 | static_cast<UnownedUserData<WebContentsView>*>( | ||
2809 | 57 | contents->GetUserData(&kUserDataKey)); | ||
2810 | 58 | if (!data) { | ||
2811 | 59 | return nullptr; | ||
2812 | 60 | } | ||
2813 | 61 | |||
2814 | 62 | return data->get(); | ||
2815 | 63 | } | ||
2816 | 64 | |||
2817 | 65 | void WebContentsView::SetContainer(RenderWidgetHostViewContainer* container) { | ||
2818 | 66 | container_ = container; | ||
2819 | 67 | RenderWidgetHostView* rwhv = | ||
2820 | 68 | static_cast<RenderWidgetHostView*>( | ||
2821 | 69 | web_contents_->GetRenderWidgetHostView()); | ||
2822 | 70 | if (rwhv) { | ||
2823 | 71 | rwhv->SetContainer(container); | ||
2824 | 72 | } | ||
2825 | 42 | } | 73 | } |
2826 | 43 | 74 | ||
2827 | 44 | gfx::NativeView WebContentsView::GetNativeView() const { | 75 | gfx::NativeView WebContentsView::GetNativeView() const { |
2828 | @@ -54,7 +85,7 @@ | |||
2829 | 54 | } | 85 | } |
2830 | 55 | 86 | ||
2831 | 56 | void WebContentsView::GetContainerBounds(gfx::Rect* out) const { | 87 | void WebContentsView::GetContainerBounds(gfx::Rect* out) const { |
2833 | 57 | *out = GetWebView()->GetViewBoundsDip(); | 88 | *out = container_->GetViewBoundsDip(); |
2834 | 58 | } | 89 | } |
2835 | 59 | 90 | ||
2836 | 60 | void WebContentsView::SizeContents(const gfx::Size& size) { | 91 | void WebContentsView::SizeContents(const gfx::Size& size) { |
2837 | @@ -107,21 +138,7 @@ | |||
2838 | 107 | content::RenderWidgetHostViewBase* WebContentsView::CreateViewForWidget( | 138 | content::RenderWidgetHostViewBase* WebContentsView::CreateViewForWidget( |
2839 | 108 | content::RenderWidgetHost* render_widget_host, | 139 | content::RenderWidgetHost* render_widget_host, |
2840 | 109 | bool is_guest_view_hack) { | 140 | bool is_guest_view_hack) { |
2856 | 110 | RenderWidgetHostView* rwhv = new RenderWidgetHostView(render_widget_host); | 141 | return new RenderWidgetHostView(render_widget_host, container_); |
2842 | 111 | |||
2843 | 112 | WebView* view = GetWebView(); | ||
2844 | 113 | if (view) { | ||
2845 | 114 | // As RWHV contains the plumbing from WebView::VisibilityChanged to | ||
2846 | 115 | // RenderWidgetHostImpl::Was{Shown,Hidden}, RWHI::is_hidden could be | ||
2847 | 116 | // out of date. This ensures that we sync RWHI::is_hidden with the | ||
2848 | 117 | // real visibility of the webview - see https://launchpad.net/bugs/1322622 | ||
2849 | 118 | view->VisibilityChanged(); | ||
2850 | 119 | |||
2851 | 120 | // Also sync focus state | ||
2852 | 121 | view->FocusChanged(); | ||
2853 | 122 | } | ||
2854 | 123 | |||
2855 | 124 | return rwhv; | ||
2857 | 125 | } | 142 | } |
2858 | 126 | 143 | ||
2859 | 127 | content::RenderWidgetHostViewBase* WebContentsView::CreateViewForPopupWidget( | 144 | content::RenderWidgetHostViewBase* WebContentsView::CreateViewForPopupWidget( |
2860 | @@ -140,7 +157,7 @@ | |||
2861 | 140 | void WebContentsView::ShowContextMenu( | 157 | void WebContentsView::ShowContextMenu( |
2862 | 141 | content::RenderFrameHost* render_frame_host, | 158 | content::RenderFrameHost* render_frame_host, |
2863 | 142 | const content::ContextMenuParams& params) { | 159 | const content::ContextMenuParams& params) { |
2865 | 143 | GetWebView()->ShowContextMenu(render_frame_host, params); | 160 | container_->ShowContextMenu(render_frame_host, params); |
2866 | 144 | } | 161 | } |
2867 | 145 | 162 | ||
2868 | 146 | void WebContentsView::StartDragging( | 163 | void WebContentsView::StartDragging( |
2869 | @@ -163,13 +180,13 @@ | |||
2870 | 163 | const std::vector<content::MenuItem>& items, | 180 | const std::vector<content::MenuItem>& items, |
2871 | 164 | bool right_aligned, | 181 | bool right_aligned, |
2872 | 165 | bool allow_multiple_selection) { | 182 | bool allow_multiple_selection) { |
2876 | 166 | GetWebView()->ShowPopupMenu(render_frame_host, | 183 | container_->ShowPopupMenu(render_frame_host, |
2877 | 167 | bounds, selected_item, items, | 184 | bounds, selected_item, items, |
2878 | 168 | allow_multiple_selection); | 185 | allow_multiple_selection); |
2879 | 169 | } | 186 | } |
2880 | 170 | 187 | ||
2881 | 171 | void WebContentsView::HidePopupMenu() { | 188 | void WebContentsView::HidePopupMenu() { |
2883 | 172 | GetWebView()->HidePopupMenu(); | 189 | container_->HidePopupMenu(); |
2884 | 173 | } | 190 | } |
2885 | 174 | 191 | ||
2886 | 175 | } // namespace oxide | 192 | } // namespace oxide |
2887 | 176 | 193 | ||
2888 | === modified file 'shared/browser/oxide_web_contents_view.h' | |||
2889 | --- shared/browser/oxide_web_contents_view.h 2015-05-28 23:51:39 +0000 | |||
2890 | +++ shared/browser/oxide_web_contents_view.h 2015-10-21 17:31:00 +0000 | |||
2891 | @@ -27,7 +27,7 @@ | |||
2892 | 27 | 27 | ||
2893 | 28 | namespace oxide { | 28 | namespace oxide { |
2894 | 29 | 29 | ||
2896 | 30 | class WebView; | 30 | class RenderWidgetHostViewContainer; |
2897 | 31 | 31 | ||
2898 | 32 | class WebContentsView final : public content::WebContentsViewOxide { | 32 | class WebContentsView final : public content::WebContentsViewOxide { |
2899 | 33 | public: | 33 | public: |
2900 | @@ -35,7 +35,9 @@ | |||
2901 | 35 | static content::WebContentsViewOxide* Create( | 35 | static content::WebContentsViewOxide* Create( |
2902 | 36 | content::WebContents* web_contents); | 36 | content::WebContents* web_contents); |
2903 | 37 | 37 | ||
2905 | 38 | WebView* GetWebView() const; | 38 | static WebContentsView* FromWebContents(content::WebContents* contents); |
2906 | 39 | |||
2907 | 40 | void SetContainer(RenderWidgetHostViewContainer* container); | ||
2908 | 39 | 41 | ||
2909 | 40 | // content::WebContentsView | 42 | // content::WebContentsView |
2910 | 41 | gfx::NativeView GetNativeView() const final; | 43 | gfx::NativeView GetNativeView() const final; |
2911 | @@ -93,6 +95,8 @@ | |||
2912 | 93 | 95 | ||
2913 | 94 | content::WebContents* web_contents_; | 96 | content::WebContents* web_contents_; |
2914 | 95 | 97 | ||
2915 | 98 | RenderWidgetHostViewContainer* container_; | ||
2916 | 99 | |||
2917 | 96 | DISALLOW_IMPLICIT_CONSTRUCTORS(WebContentsView); | 100 | DISALLOW_IMPLICIT_CONSTRUCTORS(WebContentsView); |
2918 | 97 | }; | 101 | }; |
2919 | 98 | 102 | ||
2920 | 99 | 103 | ||
2921 | === modified file 'shared/browser/oxide_web_view.cc' | |||
2922 | --- shared/browser/oxide_web_view.cc 2015-10-08 15:56:22 +0000 | |||
2923 | +++ shared/browser/oxide_web_view.cc 2015-10-21 17:31:00 +0000 | |||
2924 | @@ -25,17 +25,18 @@ | |||
2925 | 25 | #include "base/strings/string_util.h" | 25 | #include "base/strings/string_util.h" |
2926 | 26 | #include "base/strings/utf_string_conversions.h" | 26 | #include "base/strings/utf_string_conversions.h" |
2927 | 27 | #include "base/supports_user_data.h" | 27 | #include "base/supports_user_data.h" |
2928 | 28 | #include "cc/layers/layer.h" | ||
2929 | 29 | #include "cc/layers/solid_color_layer.h" | ||
2930 | 30 | #include "cc/trees/layer_tree_settings.h" | ||
2931 | 28 | #include "components/sessions/content/content_serialized_navigation_builder.h" | 31 | #include "components/sessions/content/content_serialized_navigation_builder.h" |
2932 | 29 | #include "content/browser/frame_host/render_frame_host_impl.h" | 32 | #include "content/browser/frame_host/render_frame_host_impl.h" |
2933 | 30 | #include "content/browser/renderer_host/event_with_latency_info.h" | 33 | #include "content/browser/renderer_host/event_with_latency_info.h" |
2934 | 31 | #include "content/browser/renderer_host/render_view_host_impl.h" | 34 | #include "content/browser/renderer_host/render_view_host_impl.h" |
2935 | 32 | #include "content/browser/renderer_host/render_widget_host_impl.h" | 35 | #include "content/browser/renderer_host/render_widget_host_impl.h" |
2936 | 33 | #include "content/browser/renderer_host/ui_events_helper.h" | ||
2937 | 34 | #include "content/browser/web_contents/web_contents_impl.h" | 36 | #include "content/browser/web_contents/web_contents_impl.h" |
2938 | 35 | #include "content/browser/web_contents/web_contents_view.h" | 37 | #include "content/browser/web_contents/web_contents_view.h" |
2939 | 36 | #include "content/public/browser/invalidate_type.h" | 38 | #include "content/public/browser/invalidate_type.h" |
2940 | 37 | #include "content/public/browser/browser_context.h" | 39 | #include "content/public/browser/browser_context.h" |
2941 | 38 | #include "content/public/browser/native_web_keyboard_event.h" | ||
2942 | 39 | #include "content/public/browser/navigation_controller.h" | 40 | #include "content/public/browser/navigation_controller.h" |
2943 | 40 | #include "content/public/browser/navigation_details.h" | 41 | #include "content/public/browser/navigation_details.h" |
2944 | 41 | #include "content/public/browser/navigation_entry.h" | 42 | #include "content/public/browser/navigation_entry.h" |
2945 | @@ -60,7 +61,6 @@ | |||
2946 | 60 | #include "third_party/WebKit/public/web/WebInputEvent.h" | 61 | #include "third_party/WebKit/public/web/WebInputEvent.h" |
2947 | 61 | #include "ui/base/window_open_disposition.h" | 62 | #include "ui/base/window_open_disposition.h" |
2948 | 62 | #include "ui/events/event.h" | 63 | #include "ui/events/event.h" |
2949 | 63 | #include "ui/gfx/range/range.h" | ||
2950 | 64 | #include "ui/gl/gl_implementation.h" | 64 | #include "ui/gl/gl_implementation.h" |
2951 | 65 | #include "ui/shell_dialogs/selected_file_info.h" | 65 | #include "ui/shell_dialogs/selected_file_info.h" |
2952 | 66 | #include "url/gurl.h" | 66 | #include "url/gurl.h" |
2953 | @@ -69,12 +69,15 @@ | |||
2954 | 69 | #include "shared/browser/compositor/oxide_compositor.h" | 69 | #include "shared/browser/compositor/oxide_compositor.h" |
2955 | 70 | #include "shared/browser/compositor/oxide_compositor_frame_data.h" | 70 | #include "shared/browser/compositor/oxide_compositor_frame_data.h" |
2956 | 71 | #include "shared/browser/compositor/oxide_compositor_frame_handle.h" | 71 | #include "shared/browser/compositor/oxide_compositor_frame_handle.h" |
2957 | 72 | #include "shared/browser/input/oxide_ime_bridge.h" | ||
2958 | 73 | #include "shared/browser/input/oxide_input_method_context.h" | ||
2959 | 72 | #include "shared/browser/media/oxide_media_capture_devices_dispatcher.h" | 74 | #include "shared/browser/media/oxide_media_capture_devices_dispatcher.h" |
2960 | 73 | #include "shared/browser/permissions/oxide_permission_request_dispatcher.h" | 75 | #include "shared/browser/permissions/oxide_permission_request_dispatcher.h" |
2961 | 74 | #include "shared/browser/permissions/oxide_temporary_saved_permission_context.h" | 76 | #include "shared/browser/permissions/oxide_temporary_saved_permission_context.h" |
2962 | 75 | #include "shared/common/oxide_content_client.h" | 77 | #include "shared/common/oxide_content_client.h" |
2963 | 76 | #include "shared/common/oxide_enum_flags.h" | 78 | #include "shared/common/oxide_enum_flags.h" |
2964 | 77 | #include "shared/common/oxide_messages.h" | 79 | #include "shared/common/oxide_messages.h" |
2965 | 80 | #include "shared/common/oxide_unowned_user_data.h" | ||
2966 | 78 | 81 | ||
2967 | 79 | #include "oxide_browser_context.h" | 82 | #include "oxide_browser_context.h" |
2968 | 80 | #include "oxide_browser_process_main.h" | 83 | #include "oxide_browser_process_main.h" |
2969 | @@ -106,20 +109,7 @@ | |||
2970 | 106 | 109 | ||
2971 | 107 | namespace { | 110 | namespace { |
2972 | 108 | 111 | ||
2987 | 109 | const char kWebViewKey[] = "oxide_web_view_data"; | 112 | int kUserDataKey; |
2974 | 110 | |||
2975 | 111 | // SupportsUserData implementations own their data. This class exists | ||
2976 | 112 | // because we don't want WebContents to own WebView (it's the other way | ||
2977 | 113 | // around) | ||
2978 | 114 | class WebViewUserData : public base::SupportsUserData::Data { | ||
2979 | 115 | public: | ||
2980 | 116 | WebViewUserData(WebView* view) : view_(view) {} | ||
2981 | 117 | |||
2982 | 118 | WebView* get() const { return view_; } | ||
2983 | 119 | |||
2984 | 120 | private: | ||
2985 | 121 | WebView* view_; | ||
2986 | 122 | }; | ||
2988 | 123 | 113 | ||
2989 | 124 | void FillLoadURLParamsFromOpenURLParams( | 114 | void FillLoadURLParamsFromOpenURLParams( |
2990 | 125 | content::NavigationController::LoadURLParams* load_params, | 115 | content::NavigationController::LoadURLParams* load_params, |
2991 | @@ -143,22 +133,6 @@ | |||
2992 | 143 | } | 133 | } |
2993 | 144 | } | 134 | } |
2994 | 145 | 135 | ||
2995 | 146 | // Qt input methods don’t generate key events, but a lot of web pages out there | ||
2996 | 147 | // rely on keydown and keyup events to e.g. perform search-as-you-type or | ||
2997 | 148 | // enable/disable a submit button based on the contents of a text input field, | ||
2998 | 149 | // so we send a fake pair of keydown/keyup events. | ||
2999 | 150 | // This mimicks what is done in GtkIMContextWrapper::HandlePreeditChanged(…) | ||
3000 | 151 | // and GtkIMContextWrapper::HandleCommit(…) | ||
3001 | 152 | // (see content/browser/renderer_host/gtk_im_context_wrapper.cc). | ||
3002 | 153 | void SendFakeCompositionKeyEvent(content::RenderWidgetHostImpl* host, | ||
3003 | 154 | blink::WebInputEvent::Type type) { | ||
3004 | 155 | content::NativeWebKeyboardEvent fake_event; | ||
3005 | 156 | fake_event.windowsKeyCode = ui::VKEY_PROCESSKEY; | ||
3006 | 157 | fake_event.skip_in_browser = true; | ||
3007 | 158 | fake_event.type = type; | ||
3008 | 159 | host->ForwardKeyboardEvent(fake_event); | ||
3009 | 160 | } | ||
3010 | 161 | |||
3011 | 162 | void CreateHelpers(content::WebContents* contents, | 136 | void CreateHelpers(content::WebContents* contents, |
3012 | 163 | content::WebContents* opener = nullptr) { | 137 | content::WebContents* opener = nullptr) { |
3013 | 164 | new WebViewContentsHelper(contents, opener); | 138 | new WebViewContentsHelper(contents, opener); |
3014 | @@ -225,13 +199,9 @@ | |||
3015 | 225 | 199 | ||
3016 | 226 | WebView::WebView(WebViewClient* client) | 200 | WebView::WebView(WebViewClient* client) |
3017 | 227 | : client_(client), | 201 | : client_(client), |
3018 | 228 | text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | ||
3019 | 229 | show_ime_if_needed_(false), | ||
3020 | 230 | focused_node_is_editable_(false), | ||
3021 | 231 | selection_cursor_position_(0), | ||
3022 | 232 | selection_anchor_position_(0), | ||
3023 | 233 | web_contents_helper_(nullptr), | 202 | web_contents_helper_(nullptr), |
3024 | 234 | compositor_(Compositor::Create(this)), | 203 | compositor_(Compositor::Create(this)), |
3025 | 204 | root_layer_(cc::SolidColorLayer::Create(cc::LayerSettings())), | ||
3026 | 235 | is_fullscreen_(false), | 205 | is_fullscreen_(false), |
3027 | 236 | blocked_content_(CONTENT_TYPE_NONE), | 206 | blocked_content_(CONTENT_TYPE_NONE), |
3028 | 237 | location_bar_height_pix_(0), | 207 | location_bar_height_pix_(0), |
3029 | @@ -239,6 +209,14 @@ | |||
3030 | 239 | location_bar_animated_(true), | 209 | location_bar_animated_(true), |
3031 | 240 | weak_factory_(this) { | 210 | weak_factory_(this) { |
3032 | 241 | CHECK(client) << "Didn't specify a client"; | 211 | CHECK(client) << "Didn't specify a client"; |
3033 | 212 | |||
3034 | 213 | root_layer_->SetIsDrawable(true); | ||
3035 | 214 | root_layer_->SetBackgroundColor(SK_ColorWHITE); | ||
3036 | 215 | |||
3037 | 216 | compositor_->SetRootLayer(root_layer_); | ||
3038 | 217 | |||
3039 | 218 | CompositorObserver::Observe(compositor_.get()); | ||
3040 | 219 | InputMethodContextObserver::Observe(client_->GetInputMethodContext()); | ||
3041 | 242 | } | 220 | } |
3042 | 243 | 221 | ||
3043 | 244 | void WebView::CommonInit(scoped_ptr<content::WebContents> contents) { | 222 | void WebView::CommonInit(scoped_ptr<content::WebContents> contents) { |
3044 | @@ -246,7 +224,8 @@ | |||
3045 | 246 | 224 | ||
3046 | 247 | // Attach ourself to the WebContents | 225 | // Attach ourself to the WebContents |
3047 | 248 | web_contents_->SetDelegate(this); | 226 | web_contents_->SetDelegate(this); |
3049 | 249 | web_contents_->SetUserData(kWebViewKey, new WebViewUserData(this)); | 227 | web_contents_->SetUserData(&kUserDataKey, |
3050 | 228 | new UnownedUserData<WebView>(this)); | ||
3051 | 250 | 229 | ||
3052 | 251 | content::WebContentsObserver::Observe(web_contents_.get()); | 230 | content::WebContentsObserver::Observe(web_contents_.get()); |
3053 | 252 | 231 | ||
3054 | @@ -262,6 +241,8 @@ | |||
3055 | 262 | registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, | 241 | registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, |
3056 | 263 | content::NotificationService::AllBrowserContextsAndSources()); | 242 | content::NotificationService::AllBrowserContextsAndSources()); |
3057 | 264 | 243 | ||
3058 | 244 | WebContentsView::FromWebContents(web_contents_.get())->SetContainer(this); | ||
3059 | 245 | |||
3060 | 265 | DCHECK(std::find(g_all_web_views.Get().begin(), | 246 | DCHECK(std::find(g_all_web_views.Get().begin(), |
3061 | 266 | g_all_web_views.Get().end(), | 247 | g_all_web_views.Get().end(), |
3062 | 267 | this) == | 248 | this) == |
3063 | @@ -329,11 +310,13 @@ | |||
3064 | 329 | return false; | 310 | return false; |
3065 | 330 | } | 311 | } |
3066 | 331 | 312 | ||
3068 | 332 | if (!IsInputPanelVisible()) { | 313 | if (!client_->GetInputMethodContext() || |
3069 | 314 | !client_->GetInputMethodContext()->IsInputPanelVisible()) { | ||
3070 | 333 | return false; | 315 | return false; |
3071 | 334 | } | 316 | } |
3072 | 335 | 317 | ||
3074 | 336 | if (!focused_node_is_editable_) { | 318 | if (!GetRenderWidgetHostView() || |
3075 | 319 | !GetRenderWidgetHostView()->ime_bridge()->focused_node_is_editable()) { | ||
3076 | 337 | return false; | 320 | return false; |
3077 | 338 | } | 321 | } |
3078 | 339 | 322 | ||
3079 | @@ -388,6 +371,10 @@ | |||
3080 | 388 | return client_->GetScriptMessageHandlerAt(index); | 371 | return client_->GetScriptMessageHandlerAt(index); |
3081 | 389 | } | 372 | } |
3082 | 390 | 373 | ||
3083 | 374 | void WebView::InputPanelVisibilityChanged() { | ||
3084 | 375 | MaybeScrollFocusedEditableNodeIntoView(); | ||
3085 | 376 | } | ||
3086 | 377 | |||
3087 | 391 | void WebView::CompositorDidCommit() { | 378 | void WebView::CompositorDidCommit() { |
3088 | 392 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); | 379 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
3089 | 393 | if (!rwhv) { | 380 | if (!rwhv) { |
3090 | @@ -395,8 +382,6 @@ | |||
3091 | 395 | } | 382 | } |
3092 | 396 | 383 | ||
3093 | 397 | pending_compositor_frame_metadata_ = rwhv->compositor_frame_metadata(); | 384 | pending_compositor_frame_metadata_ = rwhv->compositor_frame_metadata(); |
3094 | 398 | |||
3095 | 399 | rwhv->CompositorDidCommit(); | ||
3096 | 400 | } | 385 | } |
3097 | 401 | 386 | ||
3098 | 402 | void WebView::CompositorSwapFrame(CompositorFrameHandle* handle) { | 387 | void WebView::CompositorSwapFrame(CompositorFrameHandle* handle) { |
3099 | @@ -438,63 +423,79 @@ | |||
3100 | 438 | } | 423 | } |
3101 | 439 | } | 424 | } |
3102 | 440 | 425 | ||
3103 | 441 | void WebView::EvictCurrentFrame() { | ||
3104 | 442 | current_compositor_frame_ = nullptr; | ||
3105 | 443 | client_->EvictCurrentFrame(); | ||
3106 | 444 | } | ||
3107 | 445 | |||
3108 | 446 | void WebView::UpdateCursor(const content::WebCursor& cursor) { | ||
3109 | 447 | client_->UpdateCursor(cursor); | ||
3110 | 448 | } | ||
3111 | 449 | |||
3112 | 450 | void WebView::TextInputStateChanged(ui::TextInputType type, | ||
3113 | 451 | bool show_ime_if_needed) { | ||
3114 | 452 | if (type == text_input_type_ && | ||
3115 | 453 | show_ime_if_needed == show_ime_if_needed_) { | ||
3116 | 454 | return; | ||
3117 | 455 | } | ||
3118 | 456 | |||
3119 | 457 | text_input_type_ = type; | ||
3120 | 458 | show_ime_if_needed_ = show_ime_if_needed; | ||
3121 | 459 | |||
3122 | 460 | client_->TextInputStateChanged(); | ||
3123 | 461 | } | ||
3124 | 462 | |||
3125 | 463 | void WebView::FocusedNodeChanged(bool is_editable_node) { | ||
3126 | 464 | focused_node_is_editable_ = is_editable_node; | ||
3127 | 465 | client_->FocusedNodeChanged(); | ||
3128 | 466 | |||
3129 | 467 | MaybeScrollFocusedEditableNodeIntoView(); | ||
3130 | 468 | } | ||
3131 | 469 | |||
3132 | 470 | void WebView::ImeCancelComposition() { | ||
3133 | 471 | client_->ImeCancelComposition(); | ||
3134 | 472 | } | ||
3135 | 473 | |||
3136 | 474 | void WebView::SelectionBoundsChanged(const gfx::Rect& caret_rect, | ||
3137 | 475 | size_t selection_cursor_position, | ||
3138 | 476 | size_t selection_anchor_position) { | ||
3139 | 477 | if (caret_rect == caret_rect_ && | ||
3140 | 478 | selection_cursor_position == selection_cursor_position_ && | ||
3141 | 479 | selection_anchor_position == selection_anchor_position_) { | ||
3142 | 480 | return; | ||
3143 | 481 | } | ||
3144 | 482 | |||
3145 | 483 | caret_rect_ = caret_rect; | ||
3146 | 484 | selection_cursor_position_ = selection_cursor_position; | ||
3147 | 485 | selection_anchor_position_ = selection_anchor_position; | ||
3148 | 486 | |||
3149 | 487 | client_->SelectionBoundsChanged(); | ||
3150 | 488 | } | ||
3151 | 489 | |||
3152 | 490 | void WebView::SelectionChanged() { | ||
3153 | 491 | client_->SelectionChanged(); | ||
3154 | 492 | } | ||
3155 | 493 | |||
3156 | 494 | Compositor* WebView::GetCompositor() const { | 426 | Compositor* WebView::GetCompositor() const { |
3157 | 495 | return compositor_.get(); | 427 | return compositor_.get(); |
3158 | 496 | } | 428 | } |
3159 | 497 | 429 | ||
3160 | 430 | void WebView::AttachLayer(scoped_refptr<cc::Layer> layer) { | ||
3161 | 431 | DCHECK(layer.get()); | ||
3162 | 432 | root_layer_->InsertChild(layer, 0); | ||
3163 | 433 | root_layer_->SetIsDrawable(false); | ||
3164 | 434 | } | ||
3165 | 435 | |||
3166 | 436 | void WebView::DetachLayer(scoped_refptr<cc::Layer> layer) { | ||
3167 | 437 | DCHECK(layer.get()); | ||
3168 | 438 | DCHECK_EQ(layer->parent(), root_layer_.get()); | ||
3169 | 439 | layer->RemoveFromParent(); | ||
3170 | 440 | if (root_layer_->children().size() == 0) { | ||
3171 | 441 | root_layer_->SetIsDrawable(true); | ||
3172 | 442 | } | ||
3173 | 443 | } | ||
3174 | 444 | |||
3175 | 445 | void WebView::CursorChanged() { | ||
3176 | 446 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); | ||
3177 | 447 | if (!rwhv) { | ||
3178 | 448 | return; | ||
3179 | 449 | } | ||
3180 | 450 | |||
3181 | 451 | client_->UpdateCursor(rwhv->current_cursor()); | ||
3182 | 452 | } | ||
3183 | 453 | |||
3184 | 454 | bool WebView::HasFocus(const RenderWidgetHostView* view) const { | ||
3185 | 455 | if (!HasFocus()) { | ||
3186 | 456 | return false; | ||
3187 | 457 | } | ||
3188 | 458 | |||
3189 | 459 | return view == GetRenderWidgetHostView(); | ||
3190 | 460 | } | ||
3191 | 461 | |||
3192 | 462 | void WebView::ShowContextMenu(content::RenderFrameHost* render_frame_host, | ||
3193 | 463 | const content::ContextMenuParams& params) { | ||
3194 | 464 | WebContextMenu* menu = client_->CreateContextMenu(render_frame_host, params); | ||
3195 | 465 | if (!menu) { | ||
3196 | 466 | return; | ||
3197 | 467 | } | ||
3198 | 468 | |||
3199 | 469 | menu->Show(); | ||
3200 | 470 | } | ||
3201 | 471 | |||
3202 | 472 | void WebView::ShowPopupMenu(content::RenderFrameHost* render_frame_host, | ||
3203 | 473 | const gfx::Rect& bounds, | ||
3204 | 474 | int selected_item, | ||
3205 | 475 | const std::vector<content::MenuItem>& items, | ||
3206 | 476 | bool allow_multiple_selection) { | ||
3207 | 477 | DCHECK(!active_popup_menu_); | ||
3208 | 478 | |||
3209 | 479 | WebPopupMenu* menu = client_->CreatePopupMenu(render_frame_host); | ||
3210 | 480 | if (!menu) { | ||
3211 | 481 | static_cast<content::RenderFrameHostImpl *>( | ||
3212 | 482 | render_frame_host)->DidCancelPopupMenu(); | ||
3213 | 483 | return; | ||
3214 | 484 | } | ||
3215 | 485 | |||
3216 | 486 | active_popup_menu_ = menu->GetWeakPtr(); | ||
3217 | 487 | |||
3218 | 488 | menu->Show(bounds, items, selected_item, allow_multiple_selection); | ||
3219 | 489 | } | ||
3220 | 490 | |||
3221 | 491 | void WebView::HidePopupMenu() { | ||
3222 | 492 | if (!active_popup_menu_) { | ||
3223 | 493 | return; | ||
3224 | 494 | } | ||
3225 | 495 | |||
3226 | 496 | active_popup_menu_->Close(); | ||
3227 | 497 | } | ||
3228 | 498 | |||
3229 | 498 | content::WebContents* WebView::OpenURLFromTab( | 499 | content::WebContents* WebView::OpenURLFromTab( |
3230 | 499 | content::WebContents* source, | 500 | content::WebContents* source, |
3231 | 500 | const content::OpenURLParams& params) { | 501 | const content::OpenURLParams& params) { |
3232 | @@ -874,15 +875,31 @@ | |||
3233 | 874 | void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, | 875 | void WebView::RenderViewHostChanged(content::RenderViewHost* old_host, |
3234 | 875 | content::RenderViewHost* new_host) { | 876 | content::RenderViewHost* new_host) { |
3235 | 876 | if (old_host && old_host->GetView()) { | 877 | if (old_host && old_host->GetView()) { |
3237 | 877 | static_cast<RenderWidgetHostView *>(old_host->GetView())->SetDelegate(nullptr); | 878 | RenderWidgetHostView* rwhv = |
3238 | 879 | static_cast<RenderWidgetHostView*>(old_host->GetView()); | ||
3239 | 880 | rwhv->SetContainer(nullptr); | ||
3240 | 881 | rwhv->ime_bridge()->SetContext(nullptr); | ||
3241 | 878 | } | 882 | } |
3242 | 883 | |||
3243 | 879 | if (new_host) { | 884 | if (new_host) { |
3244 | 880 | if (new_host->GetView()) { | 885 | if (new_host->GetView()) { |
3246 | 881 | static_cast<RenderWidgetHostView *>(new_host->GetView())->SetDelegate(this); | 886 | RenderWidgetHostView* rwhv = |
3247 | 887 | static_cast<RenderWidgetHostView*>(new_host->GetView()); | ||
3248 | 888 | rwhv->SetContainer(this); | ||
3249 | 889 | rwhv->ime_bridge()->SetContext(client_->GetInputMethodContext()); | ||
3250 | 882 | } | 890 | } |
3251 | 883 | 891 | ||
3252 | 884 | InitializeTopControlsForHost(new_host, !old_host); | 892 | InitializeTopControlsForHost(new_host, !old_host); |
3253 | 885 | } | 893 | } |
3254 | 894 | |||
3255 | 895 | if (old_host) { | ||
3256 | 896 | return; | ||
3257 | 897 | } | ||
3258 | 898 | |||
3259 | 899 | // For the initial view, we need to sync its visibility and focus state | ||
3260 | 900 | // with us. For subsequent views, RFHM does this for us | ||
3261 | 901 | VisibilityChanged(); | ||
3262 | 902 | FocusChanged(); | ||
3263 | 886 | } | 903 | } |
3264 | 887 | 904 | ||
3265 | 888 | void WebView::DidStartProvisionalLoadForFrame( | 905 | void WebView::DidStartProvisionalLoadForFrame( |
3266 | @@ -1067,6 +1084,7 @@ | |||
3267 | 1067 | compositor_->SetViewportSize(GetViewSizePix()); | 1084 | compositor_->SetViewportSize(GetViewSizePix()); |
3268 | 1068 | compositor_->SetVisibility(IsVisible()); | 1085 | compositor_->SetVisibility(IsVisible()); |
3269 | 1069 | compositor_->SetDeviceScaleFactor(GetScreenInfo().deviceScaleFactor); | 1086 | compositor_->SetDeviceScaleFactor(GetScreenInfo().deviceScaleFactor); |
3270 | 1087 | root_layer_->SetBounds(GetViewSizeDip()); | ||
3271 | 1070 | 1088 | ||
3272 | 1071 | if (params.restore_entries.size() > 0) { | 1089 | if (params.restore_entries.size() > 0) { |
3273 | 1072 | ScopedVector<content::NavigationEntry> entries = | 1090 | ScopedVector<content::NavigationEntry> entries = |
3274 | @@ -1093,22 +1111,21 @@ | |||
3275 | 1093 | 1111 | ||
3276 | 1094 | CommonInit(contents.Pass()); | 1112 | CommonInit(contents.Pass()); |
3277 | 1095 | 1113 | ||
3278 | 1096 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); | ||
3279 | 1097 | if (rwhv) { | ||
3280 | 1098 | rwhv->SetDelegate(this); | ||
3281 | 1099 | } | ||
3282 | 1100 | |||
3283 | 1101 | content::RenderViewHost* rvh = GetRenderViewHost(); | 1114 | content::RenderViewHost* rvh = GetRenderViewHost(); |
3284 | 1102 | if (rvh) { | 1115 | if (rvh) { |
3285 | 1103 | InitializeTopControlsForHost(rvh, true); | 1116 | InitializeTopControlsForHost(rvh, true); |
3286 | 1104 | } | 1117 | } |
3287 | 1105 | 1118 | ||
3288 | 1119 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); | ||
3289 | 1120 | if (rwhv) { | ||
3290 | 1121 | rwhv->ime_bridge()->SetContext(client_->GetInputMethodContext()); | ||
3291 | 1122 | } | ||
3292 | 1123 | |||
3293 | 1106 | // Sync WebContents with the state of the WebView | 1124 | // Sync WebContents with the state of the WebView |
3294 | 1107 | WasResized(); | 1125 | WasResized(); |
3295 | 1108 | ScreenUpdated(); | 1126 | ScreenUpdated(); |
3296 | 1109 | VisibilityChanged(); | 1127 | VisibilityChanged(); |
3297 | 1110 | FocusChanged(); | 1128 | FocusChanged(); |
3298 | 1111 | InputPanelVisibilityChanged(); | ||
3299 | 1112 | 1129 | ||
3300 | 1113 | // Update SSL Status | 1130 | // Update SSL Status |
3301 | 1114 | content::NavigationEntry* entry = | 1131 | content::NavigationEntry* entry = |
3302 | @@ -1125,21 +1142,24 @@ | |||
3303 | 1125 | this), | 1142 | this), |
3304 | 1126 | g_all_web_views.Get().end()); | 1143 | g_all_web_views.Get().end()); |
3305 | 1127 | 1144 | ||
3306 | 1145 | WebContentsView::FromWebContents(web_contents_.get())->SetContainer(nullptr); | ||
3307 | 1146 | |||
3308 | 1128 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); | 1147 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
3309 | 1129 | if (rwhv) { | 1148 | if (rwhv) { |
3311 | 1130 | rwhv->SetDelegate(nullptr); | 1149 | rwhv->ime_bridge()->SetContext(nullptr); |
3312 | 1131 | } | 1150 | } |
3313 | 1132 | 1151 | ||
3314 | 1133 | // Stop WebContents from calling back in to us | 1152 | // Stop WebContents from calling back in to us |
3315 | 1134 | content::WebContentsObserver::Observe(nullptr); | 1153 | content::WebContentsObserver::Observe(nullptr); |
3316 | 1135 | 1154 | ||
3318 | 1136 | web_contents_->RemoveUserData(kWebViewKey); | 1155 | web_contents_->RemoveUserData(&kUserDataKey); |
3319 | 1137 | } | 1156 | } |
3320 | 1138 | 1157 | ||
3321 | 1139 | // static | 1158 | // static |
3322 | 1140 | WebView* WebView::FromWebContents(const content::WebContents* web_contents) { | 1159 | WebView* WebView::FromWebContents(const content::WebContents* web_contents) { |
3325 | 1141 | WebViewUserData* data = static_cast<WebViewUserData *>( | 1160 | UnownedUserData<WebView>* data = |
3326 | 1142 | web_contents->GetUserData(kWebViewKey)); | 1161 | static_cast<UnownedUserData<WebView>*>( |
3327 | 1162 | web_contents->GetUserData(&kUserDataKey)); | ||
3328 | 1143 | if (!data) { | 1163 | if (!data) { |
3329 | 1144 | return nullptr; | 1164 | return nullptr; |
3330 | 1145 | } | 1165 | } |
3331 | @@ -1275,11 +1295,9 @@ | |||
3332 | 1275 | } | 1295 | } |
3333 | 1276 | 1296 | ||
3334 | 1277 | void WebView::WasResized() { | 1297 | void WebView::WasResized() { |
3340 | 1278 | { | 1298 | compositor_->SetDeviceScaleFactor(GetScreenInfo().deviceScaleFactor); |
3341 | 1279 | CompositorLock lock(compositor_.get()); | 1299 | compositor_->SetViewportSize(GetViewSizePix()); |
3342 | 1280 | compositor_->SetDeviceScaleFactor(GetScreenInfo().deviceScaleFactor); | 1300 | root_layer_->SetBounds(GetViewSizeDip()); |
3338 | 1281 | compositor_->SetViewportSize(GetViewSizePix()); | ||
3339 | 1282 | } | ||
3343 | 1283 | 1301 | ||
3344 | 1284 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); | 1302 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
3345 | 1285 | if (rwhv) { | 1303 | if (rwhv) { |
3346 | @@ -1309,6 +1327,14 @@ | |||
3347 | 1309 | web_contents_->WasShown(); | 1327 | web_contents_->WasShown(); |
3348 | 1310 | } else { | 1328 | } else { |
3349 | 1311 | web_contents_->WasHidden(); | 1329 | web_contents_->WasHidden(); |
3350 | 1330 | // TODO: Have an eviction algorithm for LayerTreeHosts in Compositor, and | ||
3351 | 1331 | // trigger eviction of the frontbuffer from a CompositorClient callback. | ||
3352 | 1332 | // XXX: Also this isn't really necessary for eviction - after all, the LTH | ||
3353 | 1333 | // owned by Compositor owns the frontbuffer (via its cc::OutputSurface). | ||
3354 | 1334 | // This callback is really to notify the toolkit layer that the | ||
3355 | 1335 | // frontbuffer is being dropped | ||
3356 | 1336 | current_compositor_frame_ = nullptr; | ||
3357 | 1337 | client_->EvictCurrentFrame(); | ||
3358 | 1312 | } | 1338 | } |
3359 | 1313 | 1339 | ||
3360 | 1314 | MaybeScrollFocusedEditableNodeIntoView(); | 1340 | MaybeScrollFocusedEditableNodeIntoView(); |
3361 | @@ -1329,10 +1355,6 @@ | |||
3362 | 1329 | MaybeScrollFocusedEditableNodeIntoView(); | 1355 | MaybeScrollFocusedEditableNodeIntoView(); |
3363 | 1330 | } | 1356 | } |
3364 | 1331 | 1357 | ||
3365 | 1332 | void WebView::InputPanelVisibilityChanged() { | ||
3366 | 1333 | MaybeScrollFocusedEditableNodeIntoView(); | ||
3367 | 1334 | } | ||
3368 | 1335 | |||
3369 | 1336 | void WebView::UpdateWebPreferences() { | 1358 | void WebView::UpdateWebPreferences() { |
3370 | 1337 | content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 1359 | content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
3371 | 1338 | if (!rvh) { | 1360 | if (!rvh) { |
3372 | @@ -1605,43 +1627,6 @@ | |||
3373 | 1605 | web_contents_->DispatchBeforeUnload(false); | 1627 | web_contents_->DispatchBeforeUnload(false); |
3374 | 1606 | } | 1628 | } |
3375 | 1607 | 1629 | ||
3376 | 1608 | void WebView::ShowContextMenu(content::RenderFrameHost* render_frame_host, | ||
3377 | 1609 | const content::ContextMenuParams& params) { | ||
3378 | 1610 | WebContextMenu* menu = client_->CreateContextMenu(render_frame_host, params); | ||
3379 | 1611 | if (!menu) { | ||
3380 | 1612 | return; | ||
3381 | 1613 | } | ||
3382 | 1614 | |||
3383 | 1615 | menu->Show(); | ||
3384 | 1616 | } | ||
3385 | 1617 | |||
3386 | 1618 | void WebView::ShowPopupMenu(content::RenderFrameHost* render_frame_host, | ||
3387 | 1619 | const gfx::Rect& bounds, | ||
3388 | 1620 | int selected_item, | ||
3389 | 1621 | const std::vector<content::MenuItem>& items, | ||
3390 | 1622 | bool allow_multiple_selection) { | ||
3391 | 1623 | DCHECK(!active_popup_menu_); | ||
3392 | 1624 | |||
3393 | 1625 | WebPopupMenu* menu = client_->CreatePopupMenu(render_frame_host); | ||
3394 | 1626 | if (!menu) { | ||
3395 | 1627 | static_cast<content::RenderFrameHostImpl *>( | ||
3396 | 1628 | render_frame_host)->DidCancelPopupMenu(); | ||
3397 | 1629 | return; | ||
3398 | 1630 | } | ||
3399 | 1631 | |||
3400 | 1632 | active_popup_menu_ = menu->GetWeakPtr(); | ||
3401 | 1633 | |||
3402 | 1634 | menu->Show(bounds, items, selected_item, allow_multiple_selection); | ||
3403 | 1635 | } | ||
3404 | 1636 | |||
3405 | 1637 | void WebView::HidePopupMenu() { | ||
3406 | 1638 | if (!active_popup_menu_) { | ||
3407 | 1639 | return; | ||
3408 | 1640 | } | ||
3409 | 1641 | |||
3410 | 1642 | active_popup_menu_->Close(); | ||
3411 | 1643 | } | ||
3412 | 1644 | |||
3413 | 1645 | void WebView::AllowCertificateError( | 1630 | void WebView::AllowCertificateError( |
3414 | 1646 | content::RenderFrameHost* rfh, | 1631 | content::RenderFrameHost* rfh, |
3415 | 1647 | int cert_error, | 1632 | int cert_error, |
3416 | @@ -1727,34 +1712,6 @@ | |||
3417 | 1727 | rvh->ForwardWheelEvent(event); | 1712 | rvh->ForwardWheelEvent(event); |
3418 | 1728 | } | 1713 | } |
3419 | 1729 | 1714 | ||
3420 | 1730 | void WebView::ImeCommitText(const base::string16& text, | ||
3421 | 1731 | const gfx::Range& replacement_range) { | ||
3422 | 1732 | content::RenderWidgetHostImpl* host = GetRenderWidgetHostImpl(); | ||
3423 | 1733 | if (!host) { | ||
3424 | 1734 | return; | ||
3425 | 1735 | } | ||
3426 | 1736 | |||
3427 | 1737 | SendFakeCompositionKeyEvent(host, blink::WebInputEvent::RawKeyDown); | ||
3428 | 1738 | host->ImeConfirmComposition(text, replacement_range, false); | ||
3429 | 1739 | SendFakeCompositionKeyEvent(host, blink::WebInputEvent::KeyUp); | ||
3430 | 1740 | } | ||
3431 | 1741 | |||
3432 | 1742 | void WebView::ImeSetComposingText( | ||
3433 | 1743 | const base::string16& text, | ||
3434 | 1744 | const std::vector<blink::WebCompositionUnderline>& underlines, | ||
3435 | 1745 | const gfx::Range& selection_range) { | ||
3436 | 1746 | content::RenderWidgetHostImpl* host = GetRenderWidgetHostImpl(); | ||
3437 | 1747 | if (!host) { | ||
3438 | 1748 | return; | ||
3439 | 1749 | } | ||
3440 | 1750 | |||
3441 | 1751 | SendFakeCompositionKeyEvent(host, blink::WebInputEvent::RawKeyDown); | ||
3442 | 1752 | host->ImeSetComposition(text, underlines, | ||
3443 | 1753 | selection_range.start(), | ||
3444 | 1754 | selection_range.end()); | ||
3445 | 1755 | SendFakeCompositionKeyEvent(host, blink::WebInputEvent::KeyUp); | ||
3446 | 1756 | } | ||
3447 | 1757 | |||
3448 | 1758 | void WebView::DownloadRequested( | 1715 | void WebView::DownloadRequested( |
3449 | 1759 | const GURL& url, | 1716 | const GURL& url, |
3450 | 1760 | const std::string& mime_type, | 1717 | const std::string& mime_type, |
3451 | @@ -1810,10 +1767,6 @@ | |||
3452 | 1810 | return client_->HasFocus(); | 1767 | return client_->HasFocus(); |
3453 | 1811 | } | 1768 | } |
3454 | 1812 | 1769 | ||
3455 | 1813 | bool WebView::IsInputPanelVisible() const { | ||
3456 | 1814 | return client_->IsInputPanelVisible(); | ||
3457 | 1815 | } | ||
3458 | 1816 | |||
3459 | 1817 | JavaScriptDialog* WebView::CreateJavaScriptDialog( | 1770 | JavaScriptDialog* WebView::CreateJavaScriptDialog( |
3460 | 1818 | content::JavaScriptMessageType javascript_message_type) { | 1771 | content::JavaScriptMessageType javascript_message_type) { |
3461 | 1819 | return client_->CreateJavaScriptDialog(javascript_message_type); | 1772 | return client_->CreateJavaScriptDialog(javascript_message_type); |
3462 | @@ -1837,23 +1790,5 @@ | |||
3463 | 1837 | return client_->CanCreateWindows(); | 1790 | return client_->CanCreateWindows(); |
3464 | 1838 | } | 1791 | } |
3465 | 1839 | 1792 | ||
3466 | 1840 | base::string16 WebView::GetSelectedText() const { | ||
3467 | 1841 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); | ||
3468 | 1842 | if (!rwhv) { | ||
3469 | 1843 | return base::string16(); | ||
3470 | 1844 | } | ||
3471 | 1845 | |||
3472 | 1846 | return rwhv->GetSelectedText(); | ||
3473 | 1847 | } | ||
3474 | 1848 | |||
3475 | 1849 | const base::string16& WebView::GetSelectionText() const { | ||
3476 | 1850 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); | ||
3477 | 1851 | if (!rwhv) { | ||
3478 | 1852 | return base::EmptyString16(); | ||
3479 | 1853 | } | ||
3480 | 1854 | |||
3481 | 1855 | return rwhv->selection_text(); | ||
3482 | 1856 | } | ||
3483 | 1857 | |||
3484 | 1858 | } // namespace oxide | 1793 | } // namespace oxide |
3485 | 1859 | 1794 | ||
3486 | 1860 | 1795 | ||
3487 | === modified file 'shared/browser/oxide_web_view.h' | |||
3488 | --- shared/browser/oxide_web_view.h 2015-10-08 15:56:22 +0000 | |||
3489 | +++ shared/browser/oxide_web_view.h 2015-10-21 17:31:00 +0000 | |||
3490 | @@ -39,16 +39,16 @@ | |||
3491 | 39 | #include "content/public/common/resource_type.h" | 39 | #include "content/public/common/resource_type.h" |
3492 | 40 | #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 40 | #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
3493 | 41 | #include "third_party/WebKit/public/platform/WebTopControlsState.h" | 41 | #include "third_party/WebKit/public/platform/WebTopControlsState.h" |
3494 | 42 | #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | ||
3495 | 43 | #include "ui/base/ime/text_input_type.h" | ||
3496 | 44 | #include "ui/gfx/geometry/point.h" | 42 | #include "ui/gfx/geometry/point.h" |
3497 | 45 | #include "ui/gfx/geometry/rect.h" | 43 | #include "ui/gfx/geometry/rect.h" |
3498 | 46 | #include "ui/gfx/geometry/size.h" | 44 | #include "ui/gfx/geometry/size.h" |
3499 | 47 | 45 | ||
3500 | 48 | #include "shared/browser/compositor/oxide_compositor_client.h" | 46 | #include "shared/browser/compositor/oxide_compositor_client.h" |
3501 | 47 | #include "shared/browser/compositor/oxide_compositor_observer.h" | ||
3502 | 48 | #include "shared/browser/input/oxide_input_method_context_observer.h" | ||
3503 | 49 | #include "shared/browser/oxide_certificate_error.h" | 49 | #include "shared/browser/oxide_certificate_error.h" |
3504 | 50 | #include "shared/browser/oxide_content_types.h" | 50 | #include "shared/browser/oxide_content_types.h" |
3506 | 51 | #include "shared/browser/oxide_render_widget_host_view_delegate.h" | 51 | #include "shared/browser/oxide_render_widget_host_view_container.h" |
3507 | 52 | #include "shared/browser/oxide_script_message_target.h" | 52 | #include "shared/browser/oxide_script_message_target.h" |
3508 | 53 | #include "shared/browser/oxide_security_status.h" | 53 | #include "shared/browser/oxide_security_status.h" |
3509 | 54 | #include "shared/browser/oxide_security_types.h" | 54 | #include "shared/browser/oxide_security_types.h" |
3510 | @@ -63,10 +63,12 @@ | |||
3511 | 63 | class WebMouseWheelEvent; | 63 | class WebMouseWheelEvent; |
3512 | 64 | } // namespace blink | 64 | } // namespace blink |
3513 | 65 | 65 | ||
3514 | 66 | namespace cc { | ||
3515 | 67 | class SolidColorLayer; | ||
3516 | 68 | } | ||
3517 | 69 | |||
3518 | 66 | namespace content { | 70 | namespace content { |
3519 | 67 | 71 | ||
3520 | 68 | struct ContextMenuParams; | ||
3521 | 69 | struct MenuItem; | ||
3522 | 70 | class NativeWebKeyboardEvent; | 72 | class NativeWebKeyboardEvent; |
3523 | 71 | class NotificationRegistrar; | 73 | class NotificationRegistrar; |
3524 | 72 | struct OpenURLParams; | 74 | struct OpenURLParams; |
3525 | @@ -75,7 +77,6 @@ | |||
3526 | 75 | class RenderWidgetHostImpl; | 77 | class RenderWidgetHostImpl; |
3527 | 76 | class WebContents; | 78 | class WebContents; |
3528 | 77 | class WebContentsImpl; | 79 | class WebContentsImpl; |
3529 | 78 | class WebCursor; | ||
3530 | 79 | 80 | ||
3531 | 80 | } // namespace content | 81 | } // namespace content |
3532 | 81 | 82 | ||
3533 | @@ -129,10 +130,12 @@ | |||
3534 | 129 | // This is the main webview class. Implementations should customize this by | 130 | // This is the main webview class. Implementations should customize this by |
3535 | 130 | // providing an implementation of WebViewClient | 131 | // providing an implementation of WebViewClient |
3536 | 131 | class WebView : public ScriptMessageTarget, | 132 | class WebView : public ScriptMessageTarget, |
3537 | 133 | private InputMethodContextObserver, | ||
3538 | 134 | private CompositorObserver, | ||
3539 | 132 | private CompositorClient, | 135 | private CompositorClient, |
3540 | 133 | private WebPreferencesObserver, | 136 | private WebPreferencesObserver, |
3541 | 134 | private content::NotificationObserver, | 137 | private content::NotificationObserver, |
3543 | 135 | private RenderWidgetHostViewDelegate, | 138 | private RenderWidgetHostViewContainer, |
3544 | 136 | private content::WebContentsDelegate, | 139 | private content::WebContentsDelegate, |
3545 | 137 | private content::WebContentsObserver { | 140 | private content::WebContentsObserver { |
3546 | 138 | public: | 141 | public: |
3547 | @@ -199,7 +202,6 @@ | |||
3548 | 199 | void ScreenUpdated(); | 202 | void ScreenUpdated(); |
3549 | 200 | void VisibilityChanged(); | 203 | void VisibilityChanged(); |
3550 | 201 | void FocusChanged(); | 204 | void FocusChanged(); |
3551 | 202 | void InputPanelVisibilityChanged(); | ||
3552 | 203 | void UpdateWebPreferences(); | 205 | void UpdateWebPreferences(); |
3553 | 204 | 206 | ||
3554 | 205 | BrowserContext* GetBrowserContext() const; | 207 | BrowserContext* GetBrowserContext() const; |
3555 | @@ -259,15 +261,6 @@ | |||
3556 | 259 | 261 | ||
3557 | 260 | void PrepareToClose(); | 262 | void PrepareToClose(); |
3558 | 261 | 263 | ||
3559 | 262 | void ShowContextMenu(content::RenderFrameHost* render_frame_host, | ||
3560 | 263 | const content::ContextMenuParams& params); | ||
3561 | 264 | void ShowPopupMenu(content::RenderFrameHost* render_frame_host, | ||
3562 | 265 | const gfx::Rect& bounds, | ||
3563 | 266 | int selected_item, | ||
3564 | 267 | const std::vector<content::MenuItem>& items, | ||
3565 | 268 | bool allow_multiple_selection); | ||
3566 | 269 | void HidePopupMenu(); | ||
3567 | 270 | |||
3568 | 271 | void AllowCertificateError(content::RenderFrameHost* rfh, | 264 | void AllowCertificateError(content::RenderFrameHost* rfh, |
3569 | 272 | int cert_error, | 265 | int cert_error, |
3570 | 273 | const net::SSLInfo& ssl_info, | 266 | const net::SSLInfo& ssl_info, |
3571 | @@ -283,13 +276,6 @@ | |||
3572 | 283 | void HandleTouchEvent(const ui::TouchEvent& event); | 276 | void HandleTouchEvent(const ui::TouchEvent& event); |
3573 | 284 | void HandleWheelEvent(const blink::WebMouseWheelEvent& event); | 277 | void HandleWheelEvent(const blink::WebMouseWheelEvent& event); |
3574 | 285 | 278 | ||
3575 | 286 | void ImeCommitText(const base::string16& text, | ||
3576 | 287 | const gfx::Range& replacement_range); | ||
3577 | 288 | void ImeSetComposingText( | ||
3578 | 289 | const base::string16& text, | ||
3579 | 290 | const std::vector<blink::WebCompositionUnderline>& underlines, | ||
3580 | 291 | const gfx::Range& selection_range); | ||
3581 | 292 | |||
3582 | 293 | void DownloadRequested( | 279 | void DownloadRequested( |
3583 | 294 | const GURL& url, | 280 | const GURL& url, |
3584 | 295 | const std::string& mime_type, | 281 | const std::string& mime_type, |
3585 | @@ -309,7 +295,6 @@ | |||
3586 | 309 | gfx::Rect GetViewBoundsPix() const; | 295 | gfx::Rect GetViewBoundsPix() const; |
3587 | 310 | bool IsVisible() const; | 296 | bool IsVisible() const; |
3588 | 311 | bool HasFocus() const; | 297 | bool HasFocus() const; |
3589 | 312 | bool IsInputPanelVisible() const; | ||
3590 | 313 | 298 | ||
3591 | 314 | JavaScriptDialog* CreateJavaScriptDialog( | 299 | JavaScriptDialog* CreateJavaScriptDialog( |
3592 | 315 | content::JavaScriptMessageType javascript_message_type); | 300 | content::JavaScriptMessageType javascript_message_type); |
3593 | @@ -319,17 +304,6 @@ | |||
3594 | 319 | 304 | ||
3595 | 320 | bool CanCreateWindows() const; | 305 | bool CanCreateWindows() const; |
3596 | 321 | 306 | ||
3597 | 322 | ui::TextInputType text_input_type() const { return text_input_type_; } | ||
3598 | 323 | bool show_ime_if_needed() const { return show_ime_if_needed_; } | ||
3599 | 324 | bool focused_node_is_editable() const { return focused_node_is_editable_; } | ||
3600 | 325 | |||
3601 | 326 | gfx::Rect caret_rect() const { return caret_rect_; } | ||
3602 | 327 | size_t selection_cursor_position() const { return selection_cursor_position_; } | ||
3603 | 328 | size_t selection_anchor_position() const { return selection_anchor_position_; } | ||
3604 | 329 | |||
3605 | 330 | base::string16 GetSelectedText() const; | ||
3606 | 331 | const base::string16& GetSelectionText() const; | ||
3607 | 332 | |||
3608 | 333 | private: | 307 | private: |
3609 | 334 | WebView(WebViewClient* client); | 308 | WebView(WebViewClient* client); |
3610 | 335 | 309 | ||
3611 | @@ -364,8 +338,13 @@ | |||
3612 | 364 | virtual const ScriptMessageHandler* GetScriptMessageHandlerAt( | 338 | virtual const ScriptMessageHandler* GetScriptMessageHandlerAt( |
3613 | 365 | size_t index) const override; | 339 | size_t index) const override; |
3614 | 366 | 340 | ||
3615 | 341 | // InputMethodContextObserver implementation | ||
3616 | 342 | void InputPanelVisibilityChanged() override; | ||
3617 | 343 | |||
3618 | 344 | // CompositorObserver implementation | ||
3619 | 345 | void CompositorDidCommit() final; | ||
3620 | 346 | |||
3621 | 367 | // CompositorClient implementation | 347 | // CompositorClient implementation |
3622 | 368 | void CompositorDidCommit() final; | ||
3623 | 369 | void CompositorSwapFrame(CompositorFrameHandle* handle) final; | 348 | void CompositorSwapFrame(CompositorFrameHandle* handle) final; |
3624 | 370 | 349 | ||
3625 | 371 | // WebPreferencesObserver implementation | 350 | // WebPreferencesObserver implementation |
3626 | @@ -376,18 +355,20 @@ | |||
3627 | 376 | const content::NotificationSource& source, | 355 | const content::NotificationSource& source, |
3628 | 377 | const content::NotificationDetails& details) final; | 356 | const content::NotificationDetails& details) final; |
3629 | 378 | 357 | ||
3641 | 379 | // RenderWidgetHostViewDelegate implementation | 358 | // RenderWidgetHostViewContainer implementation |
3631 | 380 | void EvictCurrentFrame() final; | ||
3632 | 381 | void UpdateCursor(const content::WebCursor& cursor) final; | ||
3633 | 382 | void TextInputStateChanged(ui::TextInputType type, | ||
3634 | 383 | bool show_ime_if_needed) final; | ||
3635 | 384 | void FocusedNodeChanged(bool is_editable_node) final; | ||
3636 | 385 | void ImeCancelComposition() final; | ||
3637 | 386 | void SelectionBoundsChanged(const gfx::Rect& caret_rect, | ||
3638 | 387 | size_t selection_cursor_position, | ||
3639 | 388 | size_t selection_anchor_position) final; | ||
3640 | 389 | void SelectionChanged() final; | ||
3642 | 390 | Compositor* GetCompositor() const final; | 359 | Compositor* GetCompositor() const final; |
3643 | 360 | void AttachLayer(scoped_refptr<cc::Layer> layer) final; | ||
3644 | 361 | void DetachLayer(scoped_refptr<cc::Layer> layer) final; | ||
3645 | 362 | void CursorChanged() final; | ||
3646 | 363 | bool HasFocus(const RenderWidgetHostView* view) const final; | ||
3647 | 364 | void ShowContextMenu(content::RenderFrameHost* render_frame_host, | ||
3648 | 365 | const content::ContextMenuParams& params) final; | ||
3649 | 366 | void ShowPopupMenu(content::RenderFrameHost* render_frame_host, | ||
3650 | 367 | const gfx::Rect& bounds, | ||
3651 | 368 | int selected_item, | ||
3652 | 369 | const std::vector<content::MenuItem>& items, | ||
3653 | 370 | bool allow_multiple_selection) final; | ||
3654 | 371 | void HidePopupMenu() final; | ||
3655 | 391 | 372 | ||
3656 | 392 | // content::WebContentsDelegate implementation | 373 | // content::WebContentsDelegate implementation |
3657 | 393 | content::WebContents* OpenURLFromTab(content::WebContents* source, | 374 | content::WebContents* OpenURLFromTab(content::WebContents* source, |
3658 | @@ -502,14 +483,6 @@ | |||
3659 | 502 | 483 | ||
3660 | 503 | WebViewClient* client_; | 484 | WebViewClient* client_; |
3661 | 504 | 485 | ||
3662 | 505 | ui::TextInputType text_input_type_; | ||
3663 | 506 | bool show_ime_if_needed_; | ||
3664 | 507 | bool focused_node_is_editable_; | ||
3665 | 508 | |||
3666 | 509 | gfx::Rect caret_rect_; | ||
3667 | 510 | size_t selection_cursor_position_; | ||
3668 | 511 | size_t selection_anchor_position_; | ||
3669 | 512 | |||
3670 | 513 | struct WebContentsDeleter { | 486 | struct WebContentsDeleter { |
3671 | 514 | void operator()(content::WebContents* contents); | 487 | void operator()(content::WebContents* contents); |
3672 | 515 | }; | 488 | }; |
3673 | @@ -520,6 +493,7 @@ | |||
3674 | 520 | WebViewContentsHelper* web_contents_helper_; | 493 | WebViewContentsHelper* web_contents_helper_; |
3675 | 521 | 494 | ||
3676 | 522 | scoped_ptr<Compositor> compositor_; | 495 | scoped_ptr<Compositor> compositor_; |
3677 | 496 | scoped_refptr<cc::SolidColorLayer> root_layer_; | ||
3678 | 523 | 497 | ||
3679 | 524 | scoped_refptr<CompositorFrameHandle> current_compositor_frame_; | 498 | scoped_refptr<CompositorFrameHandle> current_compositor_frame_; |
3680 | 525 | std::vector<scoped_refptr<CompositorFrameHandle> > previous_compositor_frames_; | 499 | std::vector<scoped_refptr<CompositorFrameHandle> > previous_compositor_frames_; |
3681 | 526 | 500 | ||
3682 | === modified file 'shared/browser/oxide_web_view_client.cc' | |||
3683 | --- shared/browser/oxide_web_view_client.cc 2015-10-08 15:56:22 +0000 | |||
3684 | +++ shared/browser/oxide_web_view_client.cc 2015-10-21 17:31:00 +0000 | |||
3685 | @@ -23,10 +23,6 @@ | |||
3686 | 23 | 23 | ||
3687 | 24 | WebViewClient::~WebViewClient() {} | 24 | WebViewClient::~WebViewClient() {} |
3688 | 25 | 25 | ||
3689 | 26 | bool WebViewClient::IsInputPanelVisible() const { | ||
3690 | 27 | return false; | ||
3691 | 28 | } | ||
3692 | 29 | |||
3693 | 30 | JavaScriptDialog* WebViewClient::CreateJavaScriptDialog( | 26 | JavaScriptDialog* WebViewClient::CreateJavaScriptDialog( |
3694 | 31 | content::JavaScriptMessageType javascript_message_type) { | 27 | content::JavaScriptMessageType javascript_message_type) { |
3695 | 32 | return nullptr; | 28 | return nullptr; |
3696 | @@ -137,15 +133,9 @@ | |||
3697 | 137 | 133 | ||
3698 | 138 | void WebViewClient::EvictCurrentFrame() {} | 134 | void WebViewClient::EvictCurrentFrame() {} |
3699 | 139 | 135 | ||
3709 | 140 | void WebViewClient::TextInputStateChanged() {} | 136 | InputMethodContext* WebViewClient::GetInputMethodContext() const { |
3710 | 141 | 137 | return nullptr; | |
3711 | 142 | void WebViewClient::FocusedNodeChanged() {} | 138 | } |
3703 | 143 | |||
3704 | 144 | void WebViewClient::SelectionBoundsChanged() {} | ||
3705 | 145 | |||
3706 | 146 | void WebViewClient::ImeCancelComposition() {} | ||
3707 | 147 | |||
3708 | 148 | void WebViewClient::SelectionChanged() {} | ||
3712 | 149 | 139 | ||
3713 | 150 | void WebViewClient::UpdateCursor(const content::WebCursor& cursor) {} | 140 | void WebViewClient::UpdateCursor(const content::WebCursor& cursor) {} |
3714 | 151 | 141 | ||
3715 | 152 | 142 | ||
3716 | === modified file 'shared/browser/oxide_web_view_client.h' | |||
3717 | --- shared/browser/oxide_web_view_client.h 2015-10-08 15:56:22 +0000 | |||
3718 | +++ shared/browser/oxide_web_view_client.h 2015-10-21 17:31:00 +0000 | |||
3719 | @@ -48,6 +48,7 @@ | |||
3720 | 48 | 48 | ||
3721 | 49 | class CertificateError; | 49 | class CertificateError; |
3722 | 50 | class FilePicker; | 50 | class FilePicker; |
3723 | 51 | class InputMethodContext; | ||
3724 | 51 | class JavaScriptDialog; | 52 | class JavaScriptDialog; |
3725 | 52 | class ResourceDispatcherHostLoginDelegate; | 53 | class ResourceDispatcherHostLoginDelegate; |
3726 | 53 | class SecurityStatus; | 54 | class SecurityStatus; |
3727 | @@ -69,9 +70,6 @@ | |||
3728 | 69 | 70 | ||
3729 | 70 | virtual bool HasFocus() const = 0; | 71 | virtual bool HasFocus() const = 0; |
3730 | 71 | 72 | ||
3731 | 72 | // XXX(chrisccoulson): This is global state, so it doesn't belong here | ||
3732 | 73 | virtual bool IsInputPanelVisible() const; | ||
3733 | 74 | |||
3734 | 75 | // TODO(chrisccoulson): Make a delegate for JavaScriptDialogManager and move there | 73 | // TODO(chrisccoulson): Make a delegate for JavaScriptDialogManager and move there |
3735 | 76 | virtual JavaScriptDialog* CreateJavaScriptDialog( | 74 | virtual JavaScriptDialog* CreateJavaScriptDialog( |
3736 | 77 | content::JavaScriptMessageType javascript_message_type); | 75 | content::JavaScriptMessageType javascript_message_type); |
3737 | @@ -168,20 +166,7 @@ | |||
3738 | 168 | 166 | ||
3739 | 169 | virtual void EvictCurrentFrame(); | 167 | virtual void EvictCurrentFrame(); |
3740 | 170 | 168 | ||
3755 | 171 | // XXX(chrisccoulson): Rethink all of these IME related bits: | 169 | virtual InputMethodContext* GetInputMethodContext() const; |
3742 | 172 | // - Move some logic down from qt/ to shared/ | ||
3743 | 173 | // - The implementations of some of these only touch process-global | ||
3744 | 174 | // stuff - should we have an InputMethod singleton in shared/ | ||
3745 | 175 | // rather than dumping it all in WebView? | ||
3746 | 176 | virtual void TextInputStateChanged(); | ||
3747 | 177 | |||
3748 | 178 | virtual void FocusedNodeChanged(); | ||
3749 | 179 | |||
3750 | 180 | virtual void SelectionBoundsChanged(); | ||
3751 | 181 | |||
3752 | 182 | virtual void ImeCancelComposition(); | ||
3753 | 183 | |||
3754 | 184 | virtual void SelectionChanged(); | ||
3756 | 185 | 170 | ||
3757 | 186 | virtual void UpdateCursor(const content::WebCursor& cursor); | 171 | virtual void UpdateCursor(const content::WebCursor& cursor); |
3758 | 187 | 172 | ||
3759 | 188 | 173 | ||
3760 | === added file 'shared/common/oxide_unowned_user_data.h' | |||
3761 | --- shared/common/oxide_unowned_user_data.h 1970-01-01 00:00:00 +0000 | |||
3762 | +++ shared/common/oxide_unowned_user_data.h 2015-10-21 17:31:00 +0000 | |||
3763 | @@ -0,0 +1,41 @@ | |||
3764 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
3765 | 2 | // Copyright (C) 2013-2015 Canonical Ltd. | ||
3766 | 3 | |||
3767 | 4 | // This library is free software; you can redistribute it and/or | ||
3768 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
3769 | 6 | // License as published by the Free Software Foundation; either | ||
3770 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
3771 | 8 | |||
3772 | 9 | // This library is distributed in the hope that it will be useful, | ||
3773 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3774 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
3775 | 12 | // Lesser General Public License for more details. | ||
3776 | 13 | |||
3777 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
3778 | 15 | // License along with this library; if not, write to the Free Software | ||
3779 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
3780 | 17 | |||
3781 | 18 | #ifndef _OXIDE_SHARED_COMMON_UNOWNED_USER_DATA_H_ | ||
3782 | 19 | #define _OXIDE_SHARED_COMMON_UNOWNED_USER_DATA_H_ | ||
3783 | 20 | |||
3784 | 21 | #include "base/macros.h" | ||
3785 | 22 | #include "base/supports_user_data.h" | ||
3786 | 23 | |||
3787 | 24 | namespace { | ||
3788 | 25 | |||
3789 | 26 | template <class T> | ||
3790 | 27 | class UnownedUserData : public base::SupportsUserData::Data { | ||
3791 | 28 | public: | ||
3792 | 29 | UnownedUserData(T* ptr) : ptr_(ptr) {} | ||
3793 | 30 | |||
3794 | 31 | T* get() const { return ptr_; } | ||
3795 | 32 | |||
3796 | 33 | private: | ||
3797 | 34 | T* ptr_; | ||
3798 | 35 | |||
3799 | 36 | DISALLOW_COPY_AND_ASSIGN(UnownedUserData); | ||
3800 | 37 | }; | ||
3801 | 38 | |||
3802 | 39 | } // namespace oxide | ||
3803 | 40 | |||
3804 | 41 | #endif // _OXIDE_SHARED_COMMON_UNOWNED_USER_DATA_H_ | ||
3805 | 0 | 42 | ||
3806 | === modified file 'shared/shared.gyp' | |||
3807 | --- shared/shared.gyp 2015-10-08 15:56:22 +0000 | |||
3808 | +++ shared/shared.gyp 2015-10-21 17:31:00 +0000 | |||
3809 | @@ -293,6 +293,8 @@ | |||
3810 | 293 | 'browser/compositor/oxide_compositor_frame_handle.h', | 293 | 'browser/compositor/oxide_compositor_frame_handle.h', |
3811 | 294 | 'browser/compositor/oxide_compositor_gpu_shims.cc', | 294 | 'browser/compositor/oxide_compositor_gpu_shims.cc', |
3812 | 295 | 'browser/compositor/oxide_compositor_gpu_shims.h', | 295 | 'browser/compositor/oxide_compositor_gpu_shims.h', |
3813 | 296 | 'browser/compositor/oxide_compositor_observer.cc', | ||
3814 | 297 | 'browser/compositor/oxide_compositor_observer.h', | ||
3815 | 296 | 'browser/compositor/oxide_compositor_output_surface.cc', | 298 | 'browser/compositor/oxide_compositor_output_surface.cc', |
3816 | 297 | 'browser/compositor/oxide_compositor_output_surface.h', | 299 | 'browser/compositor/oxide_compositor_output_surface.h', |
3817 | 298 | 'browser/compositor/oxide_compositor_output_surface_gl.cc', | 300 | 'browser/compositor/oxide_compositor_output_surface_gl.cc', |
3818 | @@ -307,6 +309,14 @@ | |||
3819 | 307 | 'browser/compositor/oxide_compositor_utils.h', | 309 | 'browser/compositor/oxide_compositor_utils.h', |
3820 | 308 | 'browser/compositor/oxide_mailbox_buffer_map.cc', | 310 | 'browser/compositor/oxide_mailbox_buffer_map.cc', |
3821 | 309 | 'browser/compositor/oxide_mailbox_buffer_map.h', | 311 | 'browser/compositor/oxide_mailbox_buffer_map.h', |
3822 | 312 | 'browser/input/oxide_ime_bridge.cc', | ||
3823 | 313 | 'browser/input/oxide_ime_bridge.h', | ||
3824 | 314 | 'browser/input/oxide_ime_bridge_impl.cc', | ||
3825 | 315 | 'browser/input/oxide_ime_bridge_impl.h', | ||
3826 | 316 | 'browser/input/oxide_input_method_context.cc', | ||
3827 | 317 | 'browser/input/oxide_input_method_context.h', | ||
3828 | 318 | 'browser/input/oxide_input_method_context_observer.cc', | ||
3829 | 319 | 'browser/input/oxide_input_method_context_observer.h', | ||
3830 | 310 | 'browser/media/oxide_media_capture_devices_context.cc', | 320 | 'browser/media/oxide_media_capture_devices_context.cc', |
3831 | 311 | 'browser/media/oxide_media_capture_devices_context.h', | 321 | 'browser/media/oxide_media_capture_devices_context.h', |
3832 | 312 | 'browser/media/oxide_media_capture_devices_context_client.h', | 322 | 'browser/media/oxide_media_capture_devices_context_client.h', |
3833 | @@ -401,7 +411,7 @@ | |||
3834 | 401 | 'browser/oxide_render_process_initializer.h', | 411 | 'browser/oxide_render_process_initializer.h', |
3835 | 402 | 'browser/oxide_render_widget_host_view.cc', | 412 | 'browser/oxide_render_widget_host_view.cc', |
3836 | 403 | 'browser/oxide_render_widget_host_view.h', | 413 | 'browser/oxide_render_widget_host_view.h', |
3838 | 404 | 'browser/oxide_render_widget_host_view_delegate.h', | 414 | 'browser/oxide_render_widget_host_view_container.h', |
3839 | 405 | 'browser/oxide_resource_dispatcher_host_delegate.cc', | 415 | 'browser/oxide_resource_dispatcher_host_delegate.cc', |
3840 | 406 | 'browser/oxide_resource_dispatcher_host_delegate.h', | 416 | 'browser/oxide_resource_dispatcher_host_delegate.h', |
3841 | 407 | 'browser/oxide_resource_dispatcher_host_login_delegate.cc', | 417 | 'browser/oxide_resource_dispatcher_host_login_delegate.cc', |
3842 | @@ -498,6 +508,7 @@ | |||
3843 | 498 | 'common/oxide_script_message_params.h', | 508 | 'common/oxide_script_message_params.h', |
3844 | 499 | 'common/oxide_script_message_request.cc', | 509 | 'common/oxide_script_message_request.cc', |
3845 | 500 | 'common/oxide_script_message_request.h', | 510 | 'common/oxide_script_message_request.h', |
3846 | 511 | 'common/oxide_unowned_user_data.h', | ||
3847 | 501 | 'common/oxide_user_agent.cc', | 512 | 'common/oxide_user_agent.cc', |
3848 | 502 | 'common/oxide_user_agent.h', | 513 | 'common/oxide_user_agent.h', |
3849 | 503 | 'common/oxide_user_agent_override_set.cc', | 514 | 'common/oxide_user_agent_override_set.cc', |