| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/base/ime/win/imm32_manager.h" | 5 #include "ui/base/ime/win/imm32_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> |
| 10 |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/win/scoped_comptr.h" | 15 #include "base/win/scoped_comptr.h" |
| 15 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
| 16 #include "ui/base/ime/composition_text.h" | 17 #include "ui/base/ime/composition_text.h" |
| 17 | 18 |
| 18 // Following code requires wchar_t to be same as char16. It should always be | 19 // Following code requires wchar_t to be same as char16. It should always be |
| 19 // true on Windows. | 20 // true on Windows. |
| 20 static_assert(sizeof(wchar_t) == sizeof(base::char16), | 21 static_assert(sizeof(wchar_t) == sizeof(base::char16), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 | 35 |
| 35 // Helper function for IMM32Manager::GetCompositionInfo() method, to get the | 36 // Helper function for IMM32Manager::GetCompositionInfo() method, to get the |
| 36 // target range that's selected by the user in the current composition string. | 37 // target range that's selected by the user in the current composition string. |
| 37 void GetCompositionTargetRange(HIMC imm_context, int* target_start, | 38 void GetCompositionTargetRange(HIMC imm_context, int* target_start, |
| 38 int* target_end) { | 39 int* target_end) { |
| 39 int attribute_size = ::ImmGetCompositionString(imm_context, GCS_COMPATTR, | 40 int attribute_size = ::ImmGetCompositionString(imm_context, GCS_COMPATTR, |
| 40 NULL, 0); | 41 NULL, 0); |
| 41 if (attribute_size > 0) { | 42 if (attribute_size > 0) { |
| 42 int start = 0; | 43 int start = 0; |
| 43 int end = 0; | 44 int end = 0; |
| 44 scoped_ptr<char[]> attribute_data(new char[attribute_size]); | 45 std::unique_ptr<char[]> attribute_data(new char[attribute_size]); |
| 45 if (attribute_data.get()) { | 46 if (attribute_data.get()) { |
| 46 ::ImmGetCompositionString(imm_context, GCS_COMPATTR, | 47 ::ImmGetCompositionString(imm_context, GCS_COMPATTR, |
| 47 attribute_data.get(), attribute_size); | 48 attribute_data.get(), attribute_size); |
| 48 for (start = 0; start < attribute_size; ++start) { | 49 for (start = 0; start < attribute_size; ++start) { |
| 49 if (IsTargetAttribute(attribute_data[start])) | 50 if (IsTargetAttribute(attribute_data[start])) |
| 50 break; | 51 break; |
| 51 } | 52 } |
| 52 for (end = start; end < attribute_size; ++end) { | 53 for (end = start; end < attribute_size; ++end) { |
| 53 if (!IsTargetAttribute(attribute_data[end])) | 54 if (!IsTargetAttribute(attribute_data[end])) |
| 54 break; | 55 break; |
| 55 } | 56 } |
| 56 } | 57 } |
| 57 *target_start = start; | 58 *target_start = start; |
| 58 *target_end = end; | 59 *target_end = end; |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 | 62 |
| 62 // Helper function for IMM32Manager::GetCompositionInfo() method, to get | 63 // Helper function for IMM32Manager::GetCompositionInfo() method, to get |
| 63 // underlines information of the current composition string. | 64 // underlines information of the current composition string. |
| 64 void GetCompositionUnderlines(HIMC imm_context, | 65 void GetCompositionUnderlines(HIMC imm_context, |
| 65 int target_start, | 66 int target_start, |
| 66 int target_end, | 67 int target_end, |
| 67 ui::CompositionUnderlines* underlines) { | 68 ui::CompositionUnderlines* underlines) { |
| 68 int clause_size = ::ImmGetCompositionString(imm_context, GCS_COMPCLAUSE, | 69 int clause_size = ::ImmGetCompositionString(imm_context, GCS_COMPCLAUSE, |
| 69 NULL, 0); | 70 NULL, 0); |
| 70 int clause_length = clause_size / sizeof(uint32_t); | 71 int clause_length = clause_size / sizeof(uint32_t); |
| 71 if (clause_length) { | 72 if (clause_length) { |
| 72 scoped_ptr<uint32_t[]> clause_data(new uint32_t[clause_length]); | 73 std::unique_ptr<uint32_t[]> clause_data(new uint32_t[clause_length]); |
| 73 if (clause_data.get()) { | 74 if (clause_data.get()) { |
| 74 ::ImmGetCompositionString(imm_context, GCS_COMPCLAUSE, | 75 ::ImmGetCompositionString(imm_context, GCS_COMPCLAUSE, |
| 75 clause_data.get(), clause_size); | 76 clause_data.get(), clause_size); |
| 76 for (int i = 0; i < clause_length - 1; ++i) { | 77 for (int i = 0; i < clause_length - 1; ++i) { |
| 77 ui::CompositionUnderline underline; | 78 ui::CompositionUnderline underline; |
| 78 underline.start_offset = clause_data[i]; | 79 underline.start_offset = clause_data[i]; |
| 79 underline.end_offset = clause_data[i+1]; | 80 underline.end_offset = clause_data[i+1]; |
| 80 underline.color = SK_ColorBLACK; | 81 underline.color = SK_ColorBLACK; |
| 81 underline.thick = false; | 82 underline.thick = false; |
| 82 underline.background_color = SK_ColorTRANSPARENT; | 83 underline.background_color = SK_ColorTRANSPARENT; |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 | 523 |
| 523 // Retrieve the number of layouts installed in this system. | 524 // Retrieve the number of layouts installed in this system. |
| 524 int size = GetKeyboardLayoutList(0, NULL); | 525 int size = GetKeyboardLayoutList(0, NULL); |
| 525 if (size <= 0) { | 526 if (size <= 0) { |
| 526 layout = RTL_KEYBOARD_LAYOUT_ERROR; | 527 layout = RTL_KEYBOARD_LAYOUT_ERROR; |
| 527 return false; | 528 return false; |
| 528 } | 529 } |
| 529 | 530 |
| 530 // Retrieve the keyboard layouts in an array and check if there is an RTL | 531 // Retrieve the keyboard layouts in an array and check if there is an RTL |
| 531 // layout in it. | 532 // layout in it. |
| 532 scoped_ptr<HKL[]> layouts(new HKL[size]); | 533 std::unique_ptr<HKL[]> layouts(new HKL[size]); |
| 533 ::GetKeyboardLayoutList(size, layouts.get()); | 534 ::GetKeyboardLayoutList(size, layouts.get()); |
| 534 for (int i = 0; i < size; ++i) { | 535 for (int i = 0; i < size; ++i) { |
| 535 if (IsRTLPrimaryLangID( | 536 if (IsRTLPrimaryLangID( |
| 536 PRIMARYLANGID(reinterpret_cast<uintptr_t>(layouts[i])))) { | 537 PRIMARYLANGID(reinterpret_cast<uintptr_t>(layouts[i])))) { |
| 537 layout = RTL_KEYBOARD_LAYOUT_INSTALLED; | 538 layout = RTL_KEYBOARD_LAYOUT_INSTALLED; |
| 538 return true; | 539 return true; |
| 539 } | 540 } |
| 540 } | 541 } |
| 541 | 542 |
| 542 layout = RTL_KEYBOARD_LAYOUT_NOT_INSTALLED; | 543 layout = RTL_KEYBOARD_LAYOUT_NOT_INSTALLED; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 | IME_CMODE_KATAKANA | 614 | IME_CMODE_KATAKANA |
| 614 | IME_CMODE_FULLSHAPE); | 615 | IME_CMODE_FULLSHAPE); |
| 615 break; | 616 break; |
| 616 default: | 617 default: |
| 617 *open = FALSE; | 618 *open = FALSE; |
| 618 break; | 619 break; |
| 619 } | 620 } |
| 620 } | 621 } |
| 621 | 622 |
| 622 } // namespace ui | 623 } // namespace ui |
| OLD | NEW |