OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/arc/ime/arc_ime_service.h" | 5 #include "components/arc/ime/arc_ime_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "components/arc/ime/arc_ime_bridge_impl.h" | 11 #include "components/arc/ime/arc_ime_bridge_impl.h" |
12 #include "components/exo/shell_surface.h" | 12 #include "components/exo/shell_surface.h" |
13 #include "components/exo/surface.h" | 13 #include "components/exo/surface.h" |
14 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/aura/window_tree_host.h" | 16 #include "ui/aura/window_tree_host.h" |
17 #include "ui/base/ime/input_method.h" | 17 #include "ui/base/ime/input_method.h" |
18 #include "ui/events/base_event_utils.h" | 18 #include "ui/events/base_event_utils.h" |
19 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
20 #include "ui/events/keycodes/keyboard_codes.h" | 20 #include "ui/events/keycodes/keyboard_codes.h" |
21 #include "ui/gfx/range/range.h" | |
21 | 22 |
22 namespace arc { | 23 namespace arc { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 class ArcWindowDelegateImpl : public ArcImeService::ArcWindowDelegate { | 27 class ArcWindowDelegateImpl : public ArcImeService::ArcWindowDelegate { |
27 public: | 28 public: |
28 explicit ArcWindowDelegateImpl(ArcImeService* ime_service) | 29 explicit ArcWindowDelegateImpl(ArcImeService* ime_service) |
29 : ime_service_(ime_service) {} | 30 : ime_service_(ime_service) {} |
30 | 31 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 input_method->CancelComposition(this); | 225 input_method->CancelComposition(this); |
225 } | 226 } |
226 | 227 |
227 void ArcImeService::ShowImeIfNeeded() { | 228 void ArcImeService::ShowImeIfNeeded() { |
228 ui::InputMethod* const input_method = GetInputMethod(); | 229 ui::InputMethod* const input_method = GetInputMethod(); |
229 if (input_method && input_method->GetTextInputClient() == this) { | 230 if (input_method && input_method->GetTextInputClient() == this) { |
230 input_method->ShowImeIfNeeded(); | 231 input_method->ShowImeIfNeeded(); |
231 } | 232 } |
232 } | 233 } |
233 | 234 |
235 void ArcImeService::OnCursorRectChangedWithSurroundingText( | |
236 const gfx::Rect& rect, | |
237 const gfx::Range& text_range, | |
238 const base::string16& text_in_range, | |
239 const gfx::Range& selection_range) { | |
240 text_range_ = text_range; | |
hidehiko
2017/05/11 14:32:32
These values should be invalidated when the text i
yhanada
2017/05/12 07:52:06
These value should be used from InputMethod::OnCar
| |
241 text_in_range_ = text_in_range; | |
242 selection_range_ = selection_range; | |
243 OnCursorRectChanged(rect); | |
244 } | |
245 | |
234 //////////////////////////////////////////////////////////////////////////////// | 246 //////////////////////////////////////////////////////////////////////////////// |
235 // Overridden from keyboard::KeyboardControllerObserver | 247 // Overridden from keyboard::KeyboardControllerObserver |
236 void ArcImeService::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | 248 void ArcImeService::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
237 if (!focused_arc_window_) | 249 if (!focused_arc_window_) |
238 return; | 250 return; |
239 aura::Window* window = focused_arc_window_; | 251 aura::Window* window = focused_arc_window_; |
240 // Multiply by the scale factor. To convert from DPI to physical pixels. | 252 // Multiply by the scale factor. To convert from DPI to physical pixels. |
241 gfx::Rect bounds_in_px = gfx::ScaleToEnclosingRect( | 253 gfx::Rect bounds_in_px = gfx::ScaleToEnclosingRect( |
242 new_bounds, window->layer()->device_scale_factor()); | 254 new_bounds, window->layer()->device_scale_factor()); |
243 ime_bridge_->SendOnKeyboardBoundsChanging(bounds_in_px); | 255 ime_bridge_->SendOnKeyboardBoundsChanging(bounds_in_px); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 | 342 |
331 // Add the offset of the window showing the ARC app. | 343 // Add the offset of the window showing the ARC app. |
332 // TODO(yoshiki): Support for non-arc toplevel window. The following code do | 344 // TODO(yoshiki): Support for non-arc toplevel window. The following code do |
333 // not work correctly with arc windows inside non-arc toplevel window (eg. | 345 // not work correctly with arc windows inside non-arc toplevel window (eg. |
334 // notification). | 346 // notification). |
335 converted.Offset( | 347 converted.Offset( |
336 window->GetToplevelWindow()->GetBoundsInScreen().OffsetFromOrigin()); | 348 window->GetToplevelWindow()->GetBoundsInScreen().OffsetFromOrigin()); |
337 return converted; | 349 return converted; |
338 } | 350 } |
339 | 351 |
352 bool ArcImeService::GetTextRange(gfx::Range* range) const { | |
353 if (!text_range_.IsValid()) | |
354 return false; | |
355 *range = text_range_; | |
356 return true; | |
357 } | |
358 | |
359 bool ArcImeService::GetSelectionRange(gfx::Range* range) const { | |
360 if (!selection_range_.IsValid()) | |
361 return false; | |
362 *range = selection_range_; | |
363 return true; | |
364 } | |
365 | |
366 bool ArcImeService::GetTextFromRange(const gfx::Range& range, | |
367 base::string16* text) const { | |
368 if (!text_range_.IsValid() || range != text_range_) | |
hidehiko
2017/05/11 14:32:31
Could you document the limitation of the range?
(I
yhanada
2017/05/12 07:52:06
As I commented above, I suppose that this method i
| |
369 return false; | |
370 *text = text_in_range_; | |
371 return true; | |
372 } | |
373 | |
340 ui::TextInputMode ArcImeService::GetTextInputMode() const { | 374 ui::TextInputMode ArcImeService::GetTextInputMode() const { |
341 return ui::TEXT_INPUT_MODE_DEFAULT; | 375 return ui::TEXT_INPUT_MODE_DEFAULT; |
342 } | 376 } |
343 | 377 |
344 base::i18n::TextDirection ArcImeService::GetTextDirection() const { | 378 base::i18n::TextDirection ArcImeService::GetTextDirection() const { |
345 return base::i18n::UNKNOWN_DIRECTION; | 379 return base::i18n::UNKNOWN_DIRECTION; |
346 } | 380 } |
347 | 381 |
348 void ArcImeService::ExtendSelectionAndDelete(size_t before, size_t after) { | 382 void ArcImeService::ExtendSelectionAndDelete(size_t before, size_t after) { |
349 ime_bridge_->SendExtendSelectionAndDelete(before, after); | 383 ime_bridge_->SendExtendSelectionAndDelete(before, after); |
350 } | 384 } |
351 | 385 |
352 int ArcImeService::GetTextInputFlags() const { | 386 int ArcImeService::GetTextInputFlags() const { |
353 return ui::TEXT_INPUT_FLAG_NONE; | 387 return ui::TEXT_INPUT_FLAG_NONE; |
354 } | 388 } |
355 | 389 |
356 bool ArcImeService::CanComposeInline() const { | 390 bool ArcImeService::CanComposeInline() const { |
357 return true; | 391 return true; |
358 } | 392 } |
359 | 393 |
360 bool ArcImeService::GetCompositionCharacterBounds( | 394 bool ArcImeService::GetCompositionCharacterBounds( |
361 uint32_t index, gfx::Rect* rect) const { | 395 uint32_t index, gfx::Rect* rect) const { |
362 return false; | 396 return false; |
363 } | 397 } |
364 | 398 |
365 bool ArcImeService::HasCompositionText() const { | 399 bool ArcImeService::HasCompositionText() const { |
366 return has_composition_text_; | 400 return has_composition_text_; |
367 } | 401 } |
368 | 402 |
369 bool ArcImeService::GetTextRange(gfx::Range* range) const { | |
370 return false; | |
371 } | |
372 | |
373 bool ArcImeService::GetCompositionTextRange(gfx::Range* range) const { | 403 bool ArcImeService::GetCompositionTextRange(gfx::Range* range) const { |
374 return false; | 404 return false; |
375 } | 405 } |
376 | 406 |
377 bool ArcImeService::GetSelectionRange(gfx::Range* range) const { | |
378 return false; | |
379 } | |
380 | |
381 bool ArcImeService::SetSelectionRange(const gfx::Range& range) { | 407 bool ArcImeService::SetSelectionRange(const gfx::Range& range) { |
382 return false; | 408 return false; |
383 } | 409 } |
384 | 410 |
385 bool ArcImeService::DeleteRange(const gfx::Range& range) { | 411 bool ArcImeService::DeleteRange(const gfx::Range& range) { |
386 return false; | 412 return false; |
387 } | 413 } |
388 | 414 |
389 bool ArcImeService::GetTextFromRange( | |
390 const gfx::Range& range, base::string16* text) const { | |
391 return false; | |
392 } | |
393 | |
394 bool ArcImeService::ChangeTextDirectionAndLayoutAlignment( | 415 bool ArcImeService::ChangeTextDirectionAndLayoutAlignment( |
395 base::i18n::TextDirection direction) { | 416 base::i18n::TextDirection direction) { |
396 return false; | 417 return false; |
397 } | 418 } |
398 | 419 |
399 bool ArcImeService::IsTextEditCommandEnabled( | 420 bool ArcImeService::IsTextEditCommandEnabled( |
400 ui::TextEditCommand command) const { | 421 ui::TextEditCommand command) const { |
401 return false; | 422 return false; |
402 } | 423 } |
403 | 424 |
404 } // namespace arc | 425 } // namespace arc |
OLD | NEW |