Chromium Code Reviews| 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; | |
| 241 text_in_range_ = text_in_range; | |
| 242 selection_range_ = selection_range; | |
| 243 OnCursorRectChanged(rect); | |
| 244 InvalidateSurroundingTextAndSelectionRange(); | |
|
kinaba
2017/05/15 01:35:09
I guess you meant to Invalidate() in other place(s
yhanada
2017/05/15 07:42:58
Done.
| |
| 245 } | |
| 246 | |
| 234 //////////////////////////////////////////////////////////////////////////////// | 247 //////////////////////////////////////////////////////////////////////////////// |
| 235 // Overridden from keyboard::KeyboardControllerObserver | 248 // Overridden from keyboard::KeyboardControllerObserver |
| 236 void ArcImeService::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | 249 void ArcImeService::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
| 237 if (!focused_arc_window_) | 250 if (!focused_arc_window_) |
| 238 return; | 251 return; |
| 239 aura::Window* window = focused_arc_window_; | 252 aura::Window* window = focused_arc_window_; |
| 240 // Multiply by the scale factor. To convert from DPI to physical pixels. | 253 // Multiply by the scale factor. To convert from DPI to physical pixels. |
| 241 gfx::Rect bounds_in_px = gfx::ScaleToEnclosingRect( | 254 gfx::Rect bounds_in_px = gfx::ScaleToEnclosingRect( |
| 242 new_bounds, window->layer()->device_scale_factor()); | 255 new_bounds, window->layer()->device_scale_factor()); |
| 243 ime_bridge_->SendOnKeyboardBoundsChanging(bounds_in_px); | 256 ime_bridge_->SendOnKeyboardBoundsChanging(bounds_in_px); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 | 343 |
| 331 // Add the offset of the window showing the ARC app. | 344 // Add the offset of the window showing the ARC app. |
| 332 // TODO(yoshiki): Support for non-arc toplevel window. The following code do | 345 // 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. | 346 // not work correctly with arc windows inside non-arc toplevel window (eg. |
| 334 // notification). | 347 // notification). |
| 335 converted.Offset( | 348 converted.Offset( |
| 336 window->GetToplevelWindow()->GetBoundsInScreen().OffsetFromOrigin()); | 349 window->GetToplevelWindow()->GetBoundsInScreen().OffsetFromOrigin()); |
| 337 return converted; | 350 return converted; |
| 338 } | 351 } |
| 339 | 352 |
| 353 bool ArcImeService::GetTextRange(gfx::Range* range) const { | |
| 354 if (!text_range_.IsValid()) | |
| 355 return false; | |
| 356 *range = text_range_; | |
| 357 return true; | |
| 358 } | |
| 359 | |
| 360 bool ArcImeService::GetSelectionRange(gfx::Range* range) const { | |
| 361 if (!selection_range_.IsValid()) | |
| 362 return false; | |
| 363 *range = selection_range_; | |
| 364 return true; | |
| 365 } | |
| 366 | |
| 367 bool ArcImeService::GetTextFromRange(const gfx::Range& range, | |
| 368 base::string16* text) const { | |
| 369 // It's supposed that this methdo is called only from | |
|
kinaba
2017/05/15 01:35:09
methdo => method
yhanada
2017/05/15 07:42:58
Done.
| |
| 370 // InputMethod::OnCaretBoundsChanged(). In that method, the range obtained | |
| 371 // from GetTextRange() is used as the argument of this method. To prevent an | |
| 372 // unexpected usage, the check, |range != text_range_|, is added. | |
| 373 if (!text_range_.IsValid() || range != text_range_) | |
| 374 return false; | |
| 375 *text = text_in_range_; | |
| 376 return true; | |
| 377 } | |
| 378 | |
| 340 ui::TextInputMode ArcImeService::GetTextInputMode() const { | 379 ui::TextInputMode ArcImeService::GetTextInputMode() const { |
| 341 return ui::TEXT_INPUT_MODE_DEFAULT; | 380 return ui::TEXT_INPUT_MODE_DEFAULT; |
| 342 } | 381 } |
| 343 | 382 |
| 344 base::i18n::TextDirection ArcImeService::GetTextDirection() const { | 383 base::i18n::TextDirection ArcImeService::GetTextDirection() const { |
| 345 return base::i18n::UNKNOWN_DIRECTION; | 384 return base::i18n::UNKNOWN_DIRECTION; |
| 346 } | 385 } |
| 347 | 386 |
| 348 void ArcImeService::ExtendSelectionAndDelete(size_t before, size_t after) { | 387 void ArcImeService::ExtendSelectionAndDelete(size_t before, size_t after) { |
| 349 ime_bridge_->SendExtendSelectionAndDelete(before, after); | 388 ime_bridge_->SendExtendSelectionAndDelete(before, after); |
| 350 } | 389 } |
| 351 | 390 |
| 352 int ArcImeService::GetTextInputFlags() const { | 391 int ArcImeService::GetTextInputFlags() const { |
| 353 return ui::TEXT_INPUT_FLAG_NONE; | 392 return ui::TEXT_INPUT_FLAG_NONE; |
| 354 } | 393 } |
| 355 | 394 |
| 356 bool ArcImeService::CanComposeInline() const { | 395 bool ArcImeService::CanComposeInline() const { |
| 357 return true; | 396 return true; |
| 358 } | 397 } |
| 359 | 398 |
| 360 bool ArcImeService::GetCompositionCharacterBounds( | 399 bool ArcImeService::GetCompositionCharacterBounds( |
| 361 uint32_t index, gfx::Rect* rect) const { | 400 uint32_t index, gfx::Rect* rect) const { |
| 362 return false; | 401 return false; |
| 363 } | 402 } |
| 364 | 403 |
| 365 bool ArcImeService::HasCompositionText() const { | 404 bool ArcImeService::HasCompositionText() const { |
| 366 return has_composition_text_; | 405 return has_composition_text_; |
| 367 } | 406 } |
| 368 | 407 |
| 369 bool ArcImeService::GetTextRange(gfx::Range* range) const { | |
| 370 return false; | |
| 371 } | |
| 372 | |
| 373 bool ArcImeService::GetCompositionTextRange(gfx::Range* range) const { | 408 bool ArcImeService::GetCompositionTextRange(gfx::Range* range) const { |
| 374 return false; | 409 return false; |
| 375 } | 410 } |
| 376 | 411 |
| 377 bool ArcImeService::GetSelectionRange(gfx::Range* range) const { | |
| 378 return false; | |
| 379 } | |
| 380 | |
| 381 bool ArcImeService::SetSelectionRange(const gfx::Range& range) { | 412 bool ArcImeService::SetSelectionRange(const gfx::Range& range) { |
| 382 return false; | 413 return false; |
| 383 } | 414 } |
| 384 | 415 |
| 385 bool ArcImeService::DeleteRange(const gfx::Range& range) { | 416 bool ArcImeService::DeleteRange(const gfx::Range& range) { |
| 386 return false; | 417 return false; |
| 387 } | 418 } |
| 388 | 419 |
| 389 bool ArcImeService::GetTextFromRange( | |
| 390 const gfx::Range& range, base::string16* text) const { | |
| 391 return false; | |
| 392 } | |
| 393 | |
| 394 bool ArcImeService::ChangeTextDirectionAndLayoutAlignment( | 420 bool ArcImeService::ChangeTextDirectionAndLayoutAlignment( |
| 395 base::i18n::TextDirection direction) { | 421 base::i18n::TextDirection direction) { |
| 396 return false; | 422 return false; |
| 397 } | 423 } |
| 398 | 424 |
| 399 bool ArcImeService::IsTextEditCommandEnabled( | 425 bool ArcImeService::IsTextEditCommandEnabled( |
| 400 ui::TextEditCommand command) const { | 426 ui::TextEditCommand command) const { |
| 401 return false; | 427 return false; |
| 402 } | 428 } |
| 403 | 429 |
| 430 void ArcImeService::InvalidateSurroundingTextAndSelectionRange() { | |
| 431 text_range_ = gfx::Range::InvalidRange(); | |
| 432 text_in_range_ = base::ASCIIToUTF16(""); | |
|
kinaba
2017/05/15 01:35:09
base::string16()
yhanada
2017/05/15 07:42:58
Done.
| |
| 433 selection_range_ = gfx::Range::InvalidRange(); | |
| 434 } | |
| 435 | |
| 404 } // namespace arc | 436 } // namespace arc |
| OLD | NEW |