| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/chromeos/input_method/candidate_window_view.h" | 4 #include "chrome/browser/chromeos/input_method/candidate_window_view.h" |
| 5 | 5 |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/input_method/candidate_view.h" | 10 #include "chrome/browser/chromeos/input_method/candidate_view.h" |
| 11 #include "chrome/browser/chromeos/input_method/candidate_window_constants.h" | 11 #include "chrome/browser/chromeos/input_method/candidate_window_constants.h" |
| 12 #include "chrome/browser/chromeos/input_method/hidable_area.h" | 12 #include "chrome/browser/chromeos/input_method/hidable_area.h" |
| 13 #include "chrome/browser/chromeos/input_method/ibus_ui_controller.h" | 13 #include "chrome/browser/chromeos/input_method/ibus_ui_controller.h" |
| 14 #include "chromeos/dbus/ibus/ibus_lookup_table.h" |
| 14 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 15 #include "ui/views/layout/grid_layout.h" | 16 #include "ui/views/layout/grid_layout.h" |
| 16 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 17 | 18 |
| 18 namespace chromeos { | 19 namespace chromeos { |
| 19 namespace input_method { | 20 namespace input_method { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 // VerticalCandidateLabel is used for rendering candidate text in | 23 // VerticalCandidateLabel is used for rendering candidate text in |
| 23 // the vertical candidate window. | 24 // the vertical candidate window. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 views::GridLayout::FILL, views::GridLayout::FILL, | 62 views::GridLayout::FILL, views::GridLayout::FILL, |
| 62 1, views::GridLayout::USE_PREF, 0, 0); | 63 1, views::GridLayout::USE_PREF, 0, 0); |
| 63 layout->StartRow(0, 0); | 64 layout->StartRow(0, 0); |
| 64 | 65 |
| 65 // Add the view contents. | 66 // Add the view contents. |
| 66 layout->AddView(view); // |view| is owned by |wraper|, not |layout|. | 67 layout->AddView(view); // |view| is owned by |wraper|, not |layout|. |
| 67 return wrapper; | 68 return wrapper; |
| 68 } | 69 } |
| 69 | 70 |
| 70 // Creates shortcut text from the given index and the orientation. | 71 // Creates shortcut text from the given index and the orientation. |
| 71 string16 CreateShortcutText(int index, | 72 string16 CreateShortcutText(size_t index, const ibus::IBusLookupTable& table) { |
| 72 const InputMethodLookupTable& table) { | 73 if (index >= table.candidates().size()) |
| 73 if (table.labels.empty() || | |
| 74 index >= static_cast<int>(table.labels.size())) | |
| 75 return UTF8ToUTF16(""); | 74 return UTF8ToUTF16(""); |
| 76 | 75 std::string shortcut_text = table.candidates()[index].label; |
| 77 std::string shortcut_text = table.labels[index]; | 76 if (!shortcut_text.empty() && |
| 78 if (table.orientation != InputMethodLookupTable::kVertical) | 77 table.orientation() != ibus::IBusLookupTable::VERTICAL) |
| 79 shortcut_text += '.'; | 78 shortcut_text += '.'; |
| 80 return UTF8ToUTF16(shortcut_text); | 79 return UTF8ToUTF16(shortcut_text); |
| 81 } | 80 } |
| 82 | 81 |
| 83 // Creates the shortcut label, and returns it (never returns NULL). | 82 // Creates the shortcut label, and returns it (never returns NULL). |
| 84 // The label text is not set in this function. | 83 // The label text is not set in this function. |
| 85 views::Label* CreateShortcutLabel( | 84 views::Label* CreateShortcutLabel( |
| 86 InputMethodLookupTable::Orientation orientation) { | 85 ibus::IBusLookupTable::Orientation orientation) { |
| 87 // Create the shortcut label. The label will be owned by | 86 // Create the shortcut label. The label will be owned by |
| 88 // |wrapped_shortcut_label|, hence it's deleted when | 87 // |wrapped_shortcut_label|, hence it's deleted when |
| 89 // |wrapped_shortcut_label| is deleted. | 88 // |wrapped_shortcut_label| is deleted. |
| 90 views::Label* shortcut_label = new views::Label; | 89 views::Label* shortcut_label = new views::Label; |
| 91 | 90 |
| 92 if (orientation == InputMethodLookupTable::kVertical) { | 91 if (orientation == ibus::IBusLookupTable::VERTICAL) { |
| 93 shortcut_label->SetFont( | 92 shortcut_label->SetFont( |
| 94 shortcut_label->font().DeriveFont(kFontSizeDelta, gfx::Font::BOLD)); | 93 shortcut_label->font().DeriveFont(kFontSizeDelta, gfx::Font::BOLD)); |
| 95 } else { | 94 } else { |
| 96 shortcut_label->SetFont( | 95 shortcut_label->SetFont( |
| 97 shortcut_label->font().DeriveFont(kFontSizeDelta)); | 96 shortcut_label->font().DeriveFont(kFontSizeDelta)); |
| 98 } | 97 } |
| 99 // TODO(satorux): Maybe we need to use language specific fonts for | 98 // TODO(satorux): Maybe we need to use language specific fonts for |
| 100 // candidate_label, like Chinese font for Chinese input method? | 99 // candidate_label, like Chinese font for Chinese input method? |
| 101 shortcut_label->SetEnabledColor(kShortcutColor); | 100 shortcut_label->SetEnabledColor(kShortcutColor); |
| 102 shortcut_label->SetDisabledColor(kDisabledShortcutColor); | 101 shortcut_label->SetDisabledColor(kDisabledShortcutColor); |
| 103 | 102 |
| 104 return shortcut_label; | 103 return shortcut_label; |
| 105 } | 104 } |
| 106 | 105 |
| 107 // Wraps the shortcut label, then decorates wrapped shortcut label | 106 // Wraps the shortcut label, then decorates wrapped shortcut label |
| 108 // and returns it (never returns NULL). | 107 // and returns it (never returns NULL). |
| 109 // The label text is not set in this function. | 108 // The label text is not set in this function. |
| 110 views::View* CreateWrappedShortcutLabel( | 109 views::View* CreateWrappedShortcutLabel( |
| 111 views::Label* shortcut_label, | 110 views::Label* shortcut_label, |
| 112 InputMethodLookupTable::Orientation orientation) { | 111 ibus::IBusLookupTable::Orientation orientation) { |
| 113 // Wrap it with padding. | 112 // Wrap it with padding. |
| 114 const gfx::Insets kVerticalShortcutLabelInsets(1, 6, 1, 6); | 113 const gfx::Insets kVerticalShortcutLabelInsets(1, 6, 1, 6); |
| 115 const gfx::Insets kHorizontalShortcutLabelInsets(1, 3, 1, 0); | 114 const gfx::Insets kHorizontalShortcutLabelInsets(1, 3, 1, 0); |
| 116 const gfx::Insets insets = | 115 const gfx::Insets insets = |
| 117 (orientation == InputMethodLookupTable::kVertical ? | 116 (orientation == ibus::IBusLookupTable::VERTICAL ? |
| 118 kVerticalShortcutLabelInsets : | 117 kVerticalShortcutLabelInsets : |
| 119 kHorizontalShortcutLabelInsets); | 118 kHorizontalShortcutLabelInsets); |
| 120 views::View* wrapped_shortcut_label = | 119 views::View* wrapped_shortcut_label = |
| 121 WrapWithPadding(shortcut_label, insets); | 120 WrapWithPadding(shortcut_label, insets); |
| 122 | 121 |
| 123 // Add decoration based on the orientation. | 122 // Add decoration based on the orientation. |
| 124 if (orientation == InputMethodLookupTable::kVertical) { | 123 if (orientation == ibus::IBusLookupTable::VERTICAL) { |
| 125 // Set the background color. | 124 // Set the background color. |
| 126 wrapped_shortcut_label->set_background( | 125 wrapped_shortcut_label->set_background( |
| 127 views::Background::CreateSolidBackground( | 126 views::Background::CreateSolidBackground( |
| 128 kShortcutBackgroundColor)); | 127 kShortcutBackgroundColor)); |
| 129 shortcut_label->SetBackgroundColor( | 128 shortcut_label->SetBackgroundColor( |
| 130 wrapped_shortcut_label->background()->get_color()); | 129 wrapped_shortcut_label->background()->get_color()); |
| 131 } | 130 } |
| 132 | 131 |
| 133 return wrapped_shortcut_label; | 132 return wrapped_shortcut_label; |
| 134 } | 133 } |
| 135 | 134 |
| 136 // Creates the candidate label, and returns it (never returns NULL). | 135 // Creates the candidate label, and returns it (never returns NULL). |
| 137 // The label text is not set in this function. | 136 // The label text is not set in this function. |
| 138 views::Label* CreateCandidateLabel( | 137 views::Label* CreateCandidateLabel( |
| 139 InputMethodLookupTable::Orientation orientation) { | 138 ibus::IBusLookupTable::Orientation orientation) { |
| 140 views::Label* candidate_label = NULL; | 139 views::Label* candidate_label = NULL; |
| 141 | 140 |
| 142 // Create the candidate label. The label will be added to |this| as a | 141 // Create the candidate label. The label will be added to |this| as a |
| 143 // child view, hence it's deleted when |this| is deleted. | 142 // child view, hence it's deleted when |this| is deleted. |
| 144 if (orientation == InputMethodLookupTable::kVertical) { | 143 if (orientation == ibus::IBusLookupTable::VERTICAL) { |
| 145 candidate_label = new VerticalCandidateLabel; | 144 candidate_label = new VerticalCandidateLabel; |
| 146 } else { | 145 } else { |
| 147 candidate_label = new views::Label; | 146 candidate_label = new views::Label; |
| 148 } | 147 } |
| 149 | 148 |
| 150 // Change the font size. | 149 // Change the font size. |
| 151 candidate_label->SetFont( | 150 candidate_label->SetFont( |
| 152 candidate_label->font().DeriveFont(kFontSizeDelta)); | 151 candidate_label->font().DeriveFont(kFontSizeDelta)); |
| 153 candidate_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 152 candidate_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 154 | 153 |
| 155 return candidate_label; | 154 return candidate_label; |
| 156 } | 155 } |
| 157 | 156 |
| 158 // Creates the annotation label, and return it (never returns NULL). | 157 // Creates the annotation label, and return it (never returns NULL). |
| 159 // The label text is not set in this function. | 158 // The label text is not set in this function. |
| 160 views::Label* CreateAnnotationLabel( | 159 views::Label* CreateAnnotationLabel( |
| 161 InputMethodLookupTable::Orientation orientation) { | 160 ibus::IBusLookupTable::Orientation orientation) { |
| 162 // Create the annotation label. | 161 // Create the annotation label. |
| 163 views::Label* annotation_label = new views::Label; | 162 views::Label* annotation_label = new views::Label; |
| 164 | 163 |
| 165 // Change the font size and color. | 164 // Change the font size and color. |
| 166 annotation_label->SetFont( | 165 annotation_label->SetFont( |
| 167 annotation_label->font().DeriveFont(kFontSizeDelta)); | 166 annotation_label->font().DeriveFont(kFontSizeDelta)); |
| 168 annotation_label->SetEnabledColor(kAnnotationColor); | 167 annotation_label->SetEnabledColor(kAnnotationColor); |
| 169 annotation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 168 annotation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 170 | 169 |
| 171 return annotation_label; | 170 return annotation_label; |
| 172 } | 171 } |
| 173 | 172 |
| 174 // Computes shortcut column size. | 173 // Computes shortcut column size. |
| 175 gfx::Size ComputeShortcutColumnSize( | 174 gfx::Size ComputeShortcutColumnSize( |
| 176 const InputMethodLookupTable& lookup_table) { | 175 const ibus::IBusLookupTable& lookup_table) { |
| 177 int shortcut_column_width = 0; | 176 int shortcut_column_width = 0; |
| 178 int shortcut_column_height = 0; | 177 int shortcut_column_height = 0; |
| 179 // Create the shortcut label. The label will be owned by | 178 // Create the shortcut label. The label will be owned by |
| 180 // |wrapped_shortcut_label|, hence it's deleted when | 179 // |wrapped_shortcut_label|, hence it's deleted when |
| 181 // |wrapped_shortcut_label| is deleted. | 180 // |wrapped_shortcut_label| is deleted. |
| 182 views::Label* shortcut_label = CreateShortcutLabel(lookup_table.orientation); | 181 views::Label* shortcut_label = CreateShortcutLabel( |
| 182 lookup_table.orientation()); |
| 183 scoped_ptr<views::View> wrapped_shortcut_label( | 183 scoped_ptr<views::View> wrapped_shortcut_label( |
| 184 CreateWrappedShortcutLabel(shortcut_label, lookup_table.orientation)); | 184 CreateWrappedShortcutLabel(shortcut_label, lookup_table.orientation())); |
| 185 | 185 |
| 186 // Compute the max width and height in shortcut labels. | 186 // Compute the max width and height in shortcut labels. |
| 187 // We'll create temporary shortcut labels, and choose the largest width and | 187 // We'll create temporary shortcut labels, and choose the largest width and |
| 188 // height. | 188 // height. |
| 189 for (int i = 0; i < lookup_table.page_size; ++i) { | 189 for (size_t i = 0; i < lookup_table.page_size(); ++i) { |
| 190 shortcut_label->SetText(CreateShortcutText(i, lookup_table)); | 190 shortcut_label->SetText(CreateShortcutText(i, lookup_table)); |
| 191 gfx::Size text_size = wrapped_shortcut_label->GetPreferredSize(); | 191 gfx::Size text_size = wrapped_shortcut_label->GetPreferredSize(); |
| 192 shortcut_column_width = std::max(shortcut_column_width, text_size.width()); | 192 shortcut_column_width = std::max(shortcut_column_width, text_size.width()); |
| 193 shortcut_column_height = std::max(shortcut_column_height, | 193 shortcut_column_height = std::max(shortcut_column_height, |
| 194 text_size.height()); | 194 text_size.height()); |
| 195 } | 195 } |
| 196 | 196 |
| 197 return gfx::Size(shortcut_column_width, shortcut_column_height); | 197 return gfx::Size(shortcut_column_width, shortcut_column_height); |
| 198 } | 198 } |
| 199 | 199 |
| 200 // Computes the page index. For instance, if the page size is 9, and the | 200 // Computes the page index. For instance, if the page size is 9, and the |
| 201 // cursor is pointing to 13th candidate, the page index will be 1 (2nd | 201 // cursor is pointing to 13th candidate, the page index will be 1 (2nd |
| 202 // page, as the index is zero-origin). Returns -1 on error. | 202 // page, as the index is zero-origin). Returns -1 on error. |
| 203 int ComputePageIndex(const InputMethodLookupTable& lookup_table) { | 203 int ComputePageIndex(const ibus::IBusLookupTable& lookup_table) { |
| 204 if (lookup_table.page_size > 0) | 204 if (lookup_table.page_size() > 0) |
| 205 return lookup_table.cursor_absolute_index / lookup_table.page_size; | 205 return lookup_table.cursor_position() / lookup_table.page_size(); |
| 206 return -1; | 206 return -1; |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Computes candidate column size. | 209 // Computes candidate column size. |
| 210 gfx::Size ComputeCandidateColumnSize( | 210 gfx::Size ComputeCandidateColumnSize( |
| 211 const InputMethodLookupTable& lookup_table) { | 211 const ibus::IBusLookupTable& lookup_table) { |
| 212 int candidate_column_width = 0; | 212 int candidate_column_width = 0; |
| 213 int candidate_column_height = 0; | 213 int candidate_column_height = 0; |
| 214 scoped_ptr<views::Label> candidate_label( | 214 scoped_ptr<views::Label> candidate_label( |
| 215 CreateCandidateLabel(lookup_table.orientation)); | 215 CreateCandidateLabel(lookup_table.orientation())); |
| 216 | 216 |
| 217 // Compute the start index of |lookup_table_|. | 217 // Compute the start index of |lookup_table_|. |
| 218 const int current_page_index = ComputePageIndex(lookup_table); | 218 const int current_page_index = ComputePageIndex(lookup_table); |
| 219 if (current_page_index < 0) | 219 if (current_page_index < 0) |
| 220 return gfx::Size(0, 0); | 220 return gfx::Size(0, 0); |
| 221 const size_t start_from = current_page_index * lookup_table.page_size; | 221 const size_t start_from = current_page_index * lookup_table.page_size(); |
| 222 | 222 |
| 223 // Compute the max width and height in candidate labels. | 223 // Compute the max width and height in candidate labels. |
| 224 // We'll create temporary candidate labels, and choose the largest width and | 224 // We'll create temporary candidate labels, and choose the largest width and |
| 225 // height. | 225 // height. |
| 226 for (size_t i = 0; i + start_from < lookup_table.candidates.size(); ++i) { | 226 for (size_t i = 0; i + start_from < lookup_table.candidates().size(); ++i) { |
| 227 const size_t index = start_from + i; | 227 const size_t index = start_from + i; |
| 228 | 228 |
| 229 candidate_label->SetText( | 229 candidate_label->SetText( |
| 230 UTF8ToUTF16(lookup_table.candidates[index])); | 230 UTF8ToUTF16(lookup_table.candidates()[index].value)); |
| 231 gfx::Size text_size = candidate_label->GetPreferredSize(); | 231 gfx::Size text_size = candidate_label->GetPreferredSize(); |
| 232 candidate_column_width = std::max(candidate_column_width, | 232 candidate_column_width = std::max(candidate_column_width, |
| 233 text_size.width()); | 233 text_size.width()); |
| 234 candidate_column_height = std::max(candidate_column_height, | 234 candidate_column_height = std::max(candidate_column_height, |
| 235 text_size.height()); | 235 text_size.height()); |
| 236 } | 236 } |
| 237 | 237 |
| 238 return gfx::Size(candidate_column_width, candidate_column_height); | 238 return gfx::Size(candidate_column_width, candidate_column_height); |
| 239 } | 239 } |
| 240 | 240 |
| 241 // Computes annotation column size. | 241 // Computes annotation column size. |
| 242 gfx::Size ComputeAnnotationColumnSize( | 242 gfx::Size ComputeAnnotationColumnSize( |
| 243 const InputMethodLookupTable& lookup_table) { | 243 const ibus::IBusLookupTable& lookup_table) { |
| 244 int annotation_column_width = 0; | 244 int annotation_column_width = 0; |
| 245 int annotation_column_height = 0; | 245 int annotation_column_height = 0; |
| 246 scoped_ptr<views::Label> annotation_label( | 246 scoped_ptr<views::Label> annotation_label( |
| 247 CreateAnnotationLabel(lookup_table.orientation)); | 247 CreateAnnotationLabel(lookup_table.orientation())); |
| 248 | 248 |
| 249 // Compute the start index of |lookup_table_|. | 249 // Compute the start index of |lookup_table_|. |
| 250 const int current_page_index = ComputePageIndex(lookup_table); | 250 const int current_page_index = ComputePageIndex(lookup_table); |
| 251 if (current_page_index < 0) | 251 if (current_page_index < 0) |
| 252 return gfx::Size(0, 0); | 252 return gfx::Size(0, 0); |
| 253 const size_t start_from = current_page_index * lookup_table.page_size; | 253 const size_t start_from = current_page_index * lookup_table.page_size(); |
| 254 | 254 |
| 255 // Compute max width and height in annotation labels. | 255 // Compute max width and height in annotation labels. |
| 256 // We'll create temporary annotation labels, and choose the largest width and | 256 // We'll create temporary annotation labels, and choose the largest width and |
| 257 // height. | 257 // height. |
| 258 for (size_t i = 0; i + start_from < lookup_table.annotations.size(); ++i) { | 258 for (size_t i = 0; i + start_from < lookup_table.candidates().size(); ++i) { |
| 259 const size_t index = start_from + i; | 259 const size_t index = start_from + i; |
| 260 | 260 |
| 261 annotation_label->SetText( | 261 annotation_label->SetText( |
| 262 UTF8ToUTF16(lookup_table.annotations[index])); | 262 UTF8ToUTF16(lookup_table.candidates()[index].annotation)); |
| 263 gfx::Size text_size = annotation_label->GetPreferredSize(); | 263 gfx::Size text_size = annotation_label->GetPreferredSize(); |
| 264 annotation_column_width = std::max(annotation_column_width, | 264 annotation_column_width = std::max(annotation_column_width, |
| 265 text_size.width()); | 265 text_size.width()); |
| 266 annotation_column_height = std::max(annotation_column_height, | 266 annotation_column_height = std::max(annotation_column_height, |
| 267 text_size.height()); | 267 text_size.height()); |
| 268 } | 268 } |
| 269 | 269 |
| 270 return gfx::Size(annotation_column_width, annotation_column_height); | 270 return gfx::Size(annotation_column_width, annotation_column_height); |
| 271 } | 271 } |
| 272 | 272 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 private: | 312 private: |
| 313 views::Label* label_; | 313 views::Label* label_; |
| 314 int minWidth_; | 314 int minWidth_; |
| 315 | 315 |
| 316 DISALLOW_COPY_AND_ASSIGN(InformationTextArea); | 316 DISALLOW_COPY_AND_ASSIGN(InformationTextArea); |
| 317 }; | 317 }; |
| 318 | 318 |
| 319 CandidateView::CandidateView( | 319 CandidateView::CandidateView( |
| 320 CandidateWindowView* parent_candidate_window, | 320 CandidateWindowView* parent_candidate_window, |
| 321 int index_in_page, | 321 int index_in_page, |
| 322 InputMethodLookupTable::Orientation orientation) | 322 ibus::IBusLookupTable::Orientation orientation) |
| 323 : index_in_page_(index_in_page), | 323 : index_in_page_(index_in_page), |
| 324 orientation_(orientation), | 324 orientation_(orientation), |
| 325 parent_candidate_window_(parent_candidate_window), | 325 parent_candidate_window_(parent_candidate_window), |
| 326 shortcut_label_(NULL), | 326 shortcut_label_(NULL), |
| 327 candidate_label_(NULL), | 327 candidate_label_(NULL), |
| 328 annotation_label_(NULL), | 328 annotation_label_(NULL), |
| 329 infolist_icon_(NULL), | 329 infolist_icon_(NULL), |
| 330 infolist_icon_enabled_(false) { | 330 infolist_icon_enabled_(false) { |
| 331 } | 331 } |
| 332 | 332 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 343 CreateWrappedShortcutLabel(shortcut_label_, orientation_); | 343 CreateWrappedShortcutLabel(shortcut_label_, orientation_); |
| 344 candidate_label_ = CreateCandidateLabel(orientation_); | 344 candidate_label_ = CreateCandidateLabel(orientation_); |
| 345 annotation_label_ = CreateAnnotationLabel(orientation_); | 345 annotation_label_ = CreateAnnotationLabel(orientation_); |
| 346 | 346 |
| 347 // Initialize the column set with three columns. | 347 // Initialize the column set with three columns. |
| 348 views::ColumnSet* column_set = layout->AddColumnSet(0); | 348 views::ColumnSet* column_set = layout->AddColumnSet(0); |
| 349 | 349 |
| 350 // If orientation is vertical, each column width is fixed. | 350 // If orientation is vertical, each column width is fixed. |
| 351 // Otherwise the width is resizable. | 351 // Otherwise the width is resizable. |
| 352 const views::GridLayout::SizeType column_type = | 352 const views::GridLayout::SizeType column_type = |
| 353 orientation_ == InputMethodLookupTable::kVertical ? | 353 orientation_ == ibus::IBusLookupTable::VERTICAL ? |
| 354 views::GridLayout::FIXED : views::GridLayout::USE_PREF; | 354 views::GridLayout::FIXED : views::GridLayout::USE_PREF; |
| 355 | 355 |
| 356 const int padding_column_width = | 356 const int padding_column_width = |
| 357 orientation_ == InputMethodLookupTable::kVertical ? 4 : 6; | 357 orientation_ == ibus::IBusLookupTable::VERTICAL ? 4 : 6; |
| 358 | 358 |
| 359 // Set shortcut column type and width. | 359 // Set shortcut column type and width. |
| 360 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 360 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
| 361 0, column_type, shortcut_column_width, 0); | 361 0, column_type, shortcut_column_width, 0); |
| 362 column_set->AddPaddingColumn(0, padding_column_width); | 362 column_set->AddPaddingColumn(0, padding_column_width); |
| 363 | 363 |
| 364 // Set candidate column type and width. | 364 // Set candidate column type and width. |
| 365 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 365 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
| 366 0, column_type, candidate_column_width, 0); | 366 0, column_type, candidate_column_width, 0); |
| 367 column_set->AddPaddingColumn(0, padding_column_width); | 367 column_set->AddPaddingColumn(0, padding_column_width); |
| 368 | 368 |
| 369 // Set annotation column type and width. | 369 // Set annotation column type and width. |
| 370 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 370 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
| 371 0, column_type, annotation_column_width, 0); | 371 0, column_type, annotation_column_width, 0); |
| 372 | 372 |
| 373 if (orientation_ == InputMethodLookupTable::kVertical) { | 373 if (orientation_ == ibus::IBusLookupTable::VERTICAL) { |
| 374 column_set->AddPaddingColumn(0, 1); | 374 column_set->AddPaddingColumn(0, 1); |
| 375 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 375 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
| 376 views::GridLayout::FIXED, kInfolistIndicatorIconWidth, | 376 views::GridLayout::FIXED, kInfolistIndicatorIconWidth, |
| 377 0); | 377 0); |
| 378 column_set->AddPaddingColumn(0, 2); | 378 column_set->AddPaddingColumn(0, 2); |
| 379 } else { | 379 } else { |
| 380 column_set->AddPaddingColumn(0, padding_column_width); | 380 column_set->AddPaddingColumn(0, padding_column_width); |
| 381 } | 381 } |
| 382 | 382 |
| 383 // Add the shortcut label, the candidate label, and annotation label. | 383 // Add the shortcut label, the candidate label, and annotation label. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 398 views::GridLayout::FILL, // Vertical alignment. | 398 views::GridLayout::FILL, // Vertical alignment. |
| 399 -1, // Preferred width, not specified. | 399 -1, // Preferred width, not specified. |
| 400 column_height); // Preferred height. | 400 column_height); // Preferred height. |
| 401 layout->AddView(annotation_label_, | 401 layout->AddView(annotation_label_, |
| 402 1, // Column span. | 402 1, // Column span. |
| 403 1, // Row span. | 403 1, // Row span. |
| 404 views::GridLayout::FILL, // Horizontal alignment. | 404 views::GridLayout::FILL, // Horizontal alignment. |
| 405 views::GridLayout::FILL, // Vertical alignemnt. | 405 views::GridLayout::FILL, // Vertical alignemnt. |
| 406 -1, // Preferred width, not specified. | 406 -1, // Preferred width, not specified. |
| 407 column_height); // Preferred height. | 407 column_height); // Preferred height. |
| 408 if (orientation_ == InputMethodLookupTable::kVertical) { | 408 if (orientation_ == ibus::IBusLookupTable::VERTICAL) { |
| 409 infolist_icon_ = new views::View; | 409 infolist_icon_ = new views::View; |
| 410 views::View* infolist_icon_wrapper = new views::View; | 410 views::View* infolist_icon_wrapper = new views::View; |
| 411 views::GridLayout* infolist_icon_layout = | 411 views::GridLayout* infolist_icon_layout = |
| 412 new views::GridLayout(infolist_icon_wrapper); | 412 new views::GridLayout(infolist_icon_wrapper); |
| 413 // |infolist_icon_layout| is owned by |infolist_icon_wrapper|. | 413 // |infolist_icon_layout| is owned by |infolist_icon_wrapper|. |
| 414 infolist_icon_wrapper->SetLayoutManager(infolist_icon_layout); | 414 infolist_icon_wrapper->SetLayoutManager(infolist_icon_layout); |
| 415 infolist_icon_layout->AddColumnSet(0)->AddColumn( | 415 infolist_icon_layout->AddColumnSet(0)->AddColumn( |
| 416 views::GridLayout::FILL, views::GridLayout::FILL, | 416 views::GridLayout::FILL, views::GridLayout::FILL, |
| 417 0, views::GridLayout::FIXED, kInfolistIndicatorIconWidth, 0); | 417 0, views::GridLayout::FIXED, kInfolistIndicatorIconWidth, 0); |
| 418 infolist_icon_layout->AddPaddingRow(0, kInfolistIndicatorIconPadding); | 418 infolist_icon_layout->AddPaddingRow(0, kInfolistIndicatorIconPadding); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 views::View::ConvertPointToTarget(this, parent_candidate_window_, | 511 views::View::ConvertPointToTarget(this, parent_candidate_window_, |
| 512 &location_in_candidate_window); | 512 &location_in_candidate_window); |
| 513 parent_candidate_window_->OnCandidatePressed(location_in_candidate_window); | 513 parent_candidate_window_->OnCandidatePressed(location_in_candidate_window); |
| 514 parent_candidate_window_->CommitCandidate(); | 514 parent_candidate_window_->CommitCandidate(); |
| 515 return false; | 515 return false; |
| 516 } | 516 } |
| 517 | 517 |
| 518 void CandidateView::UpdateLabelBackgroundColors() { | 518 void CandidateView::UpdateLabelBackgroundColors() { |
| 519 SkColor color = background() ? | 519 SkColor color = background() ? |
| 520 background()->get_color() : kDefaultBackgroundColor; | 520 background()->get_color() : kDefaultBackgroundColor; |
| 521 if (orientation_ != InputMethodLookupTable::kVertical) | 521 if (orientation_ != ibus::IBusLookupTable::VERTICAL) |
| 522 shortcut_label_->SetBackgroundColor(color); | 522 shortcut_label_->SetBackgroundColor(color); |
| 523 candidate_label_->SetBackgroundColor(color); | 523 candidate_label_->SetBackgroundColor(color); |
| 524 annotation_label_->SetBackgroundColor(color); | 524 annotation_label_->SetBackgroundColor(color); |
| 525 } | 525 } |
| 526 | 526 |
| 527 CandidateWindowView::CandidateWindowView(views::Widget* parent_frame) | 527 CandidateWindowView::CandidateWindowView(views::Widget* parent_frame) |
| 528 : selected_candidate_index_in_page_(0), | 528 : selected_candidate_index_in_page_(0), |
| 529 parent_frame_(parent_frame), | 529 parent_frame_(parent_frame), |
| 530 preedit_area_(NULL), | 530 preedit_area_(NULL), |
| 531 header_area_(NULL), | 531 header_area_(NULL), |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 } | 610 } |
| 611 | 611 |
| 612 void CandidateWindowView::ShowAuxiliaryText() { | 612 void CandidateWindowView::ShowAuxiliaryText() { |
| 613 // If candidate_area is not shown, shows auxiliary text at header_area. | 613 // If candidate_area is not shown, shows auxiliary text at header_area. |
| 614 // We expect both header_area_ and footer_area_ contain same value. | 614 // We expect both header_area_ and footer_area_ contain same value. |
| 615 if (!candidate_area_->IsShown()) { | 615 if (!candidate_area_->IsShown()) { |
| 616 header_area_->Show(); | 616 header_area_->Show(); |
| 617 footer_area_->Hide(); | 617 footer_area_->Hide(); |
| 618 } else { | 618 } else { |
| 619 // If candidate_area is shown, shows auxiliary text with orientation. | 619 // If candidate_area is shown, shows auxiliary text with orientation. |
| 620 if (lookup_table_.orientation == InputMethodLookupTable::kHorizontal) { | 620 if (lookup_table_.orientation() == ibus::IBusLookupTable::HORIZONTAL) { |
| 621 header_area_->Show(); | 621 header_area_->Show(); |
| 622 footer_area_->Hide(); | 622 footer_area_->Hide(); |
| 623 } else { | 623 } else { |
| 624 footer_area_->Show(); | 624 footer_area_->Show(); |
| 625 header_area_->Hide(); | 625 header_area_->Hide(); |
| 626 } | 626 } |
| 627 } | 627 } |
| 628 UpdateParentArea(); | 628 UpdateParentArea(); |
| 629 } | 629 } |
| 630 | 630 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 659 bool is_open = IsCandidateWindowOpen(); | 659 bool is_open = IsCandidateWindowOpen(); |
| 660 if (!was_candidate_window_open_ && is_open) { | 660 if (!was_candidate_window_open_ && is_open) { |
| 661 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowOpened()); | 661 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowOpened()); |
| 662 } else if (was_candidate_window_open_ && !is_open) { | 662 } else if (was_candidate_window_open_ && !is_open) { |
| 663 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowClosed()); | 663 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateWindowClosed()); |
| 664 } | 664 } |
| 665 was_candidate_window_open_ = is_open; | 665 was_candidate_window_open_ = is_open; |
| 666 } | 666 } |
| 667 | 667 |
| 668 bool CandidateWindowView::ShouldUpdateCandidateViews( | 668 bool CandidateWindowView::ShouldUpdateCandidateViews( |
| 669 const InputMethodLookupTable& old_table, | 669 const ibus::IBusLookupTable& old_table, |
| 670 const InputMethodLookupTable& new_table) { | 670 const ibus::IBusLookupTable& new_table) { |
| 671 | 671 return !old_table.IsEqual(new_table); |
| 672 // Check if most table contents are identical. | |
| 673 if (old_table.page_size == new_table.page_size && | |
| 674 old_table.orientation == new_table.orientation && | |
| 675 old_table.candidates == new_table.candidates && | |
| 676 old_table.labels == new_table.labels && | |
| 677 old_table.annotations == new_table.annotations && | |
| 678 old_table.descriptions.size() == new_table.descriptions.size() && | |
| 679 // Check if the page indexes are identical. | |
| 680 ComputePageIndex(old_table) == ComputePageIndex(new_table)) { | |
| 681 for (size_t i = 0; i < new_table.descriptions.size(); ++i) { | |
| 682 if (old_table.descriptions[i].title != new_table.descriptions[i].title || | |
| 683 old_table.descriptions[i].body != new_table.descriptions[i].body) | |
| 684 return true; | |
| 685 } | |
| 686 // If all of the conditions are met, we don't have to update candidate | |
| 687 // views. | |
| 688 return false; | |
| 689 } | |
| 690 return true; | |
| 691 } | 672 } |
| 692 | 673 |
| 693 void CandidateWindowView::UpdateCandidates( | 674 void CandidateWindowView::UpdateCandidates( |
| 694 const InputMethodLookupTable& new_lookup_table) { | 675 const ibus::IBusLookupTable& new_lookup_table) { |
| 695 const bool should_update = ShouldUpdateCandidateViews(lookup_table_, | 676 const bool should_update = ShouldUpdateCandidateViews(lookup_table_, |
| 696 new_lookup_table); | 677 new_lookup_table); |
| 697 // Updating the candidate views is expensive. We'll skip this if possible. | 678 // Updating the candidate views is expensive. We'll skip this if possible. |
| 698 if (should_update) { | 679 if (should_update) { |
| 699 // Initialize candidate views if necessary. | 680 // Initialize candidate views if necessary. |
| 700 MaybeInitializeCandidateViews(new_lookup_table); | 681 MaybeInitializeCandidateViews(new_lookup_table); |
| 701 | 682 |
| 702 should_show_at_composition_head_ | 683 should_show_at_composition_head_ |
| 703 = new_lookup_table.show_at_composition_head; | 684 = new_lookup_table.show_window_at_composition(); |
| 704 // Compute the index of the current page. | 685 // Compute the index of the current page. |
| 705 const int current_page_index = ComputePageIndex(new_lookup_table); | 686 const int current_page_index = ComputePageIndex(new_lookup_table); |
| 706 if (current_page_index < 0) { | 687 if (current_page_index < 0) { |
| 707 DVLOG(1) << "Invalid lookup_table: " << new_lookup_table.ToString(); | |
| 708 return; | 688 return; |
| 709 } | 689 } |
| 710 | 690 |
| 711 // Update the candidates in the current page. | 691 // Update the candidates in the current page. |
| 712 const size_t start_from = current_page_index * new_lookup_table.page_size; | 692 const size_t start_from = current_page_index * new_lookup_table.page_size(); |
| 713 | 693 |
| 714 // In some cases, engines send empty shortcut labels. For instance, | 694 // In some cases, engines send empty shortcut labels. For instance, |
| 715 // ibus-mozc sends empty labels when they show suggestions. In this | 695 // ibus-mozc sends empty labels when they show suggestions. In this |
| 716 // case, we should not show shortcut labels. | 696 // case, we should not show shortcut labels. |
| 717 const bool no_shortcut_mode = | 697 bool no_shortcut_mode = true; |
| 718 (start_from < new_lookup_table.labels.size() && | 698 for (size_t i = 0; i < new_lookup_table.candidates().size(); ++i) { |
| 719 new_lookup_table.labels[start_from].empty()); | 699 if (!new_lookup_table.candidates()[i].label.empty()) { |
| 700 no_shortcut_mode = false; |
| 701 break; |
| 702 } |
| 703 } |
| 704 |
| 720 for (size_t i = 0; i < candidate_views_.size(); ++i) { | 705 for (size_t i = 0; i < candidate_views_.size(); ++i) { |
| 721 const size_t index_in_page = i; | 706 const size_t index_in_page = i; |
| 722 const size_t candidate_index = start_from + index_in_page; | 707 const size_t candidate_index = start_from + index_in_page; |
| 723 CandidateView* candidate_view = candidate_views_[index_in_page]; | 708 CandidateView* candidate_view = candidate_views_[index_in_page]; |
| 724 // Set the shortcut text. | 709 // Set the shortcut text. |
| 725 if (no_shortcut_mode) { | 710 if (no_shortcut_mode) { |
| 726 candidate_view->SetShortcutText(string16()); | 711 candidate_view->SetShortcutText(string16()); |
| 727 } else { | 712 } else { |
| 728 // At this moment, we don't use labels sent from engines for UX | 713 // At this moment, we don't use labels sent from engines for UX |
| 729 // reasons. First, we want to show shortcut labels in empty rows | 714 // reasons. First, we want to show shortcut labels in empty rows |
| 730 // (ex. show 6, 7, 8, ... in empty rows when the number of | 715 // (ex. show 6, 7, 8, ... in empty rows when the number of |
| 731 // candidates is 5). Second, we want to add a period after each | 716 // candidates is 5). Second, we want to add a period after each |
| 732 // shortcut label when the candidate window is horizontal. | 717 // shortcut label when the candidate window is horizontal. |
| 733 candidate_view->SetShortcutText( | 718 candidate_view->SetShortcutText( |
| 734 CreateShortcutText(i, new_lookup_table)); | 719 CreateShortcutText(i, new_lookup_table)); |
| 735 } | 720 } |
| 736 // Set the candidate text. | 721 // Set the candidate text. |
| 737 if (candidate_index < new_lookup_table.candidates.size() && | 722 if (candidate_index < new_lookup_table.candidates().size()) { |
| 738 candidate_index < new_lookup_table.annotations.size()) { | 723 const ibus::IBusLookupTable::Entry& entry = |
| 739 candidate_view->SetCandidateText( | 724 new_lookup_table.candidates()[candidate_index]; |
| 740 UTF8ToUTF16(new_lookup_table.candidates[candidate_index])); | 725 candidate_view->SetCandidateText(UTF8ToUTF16(entry.value)); |
| 741 candidate_view->SetAnnotationText( | 726 candidate_view->SetAnnotationText(UTF8ToUTF16(entry.annotation)); |
| 742 UTF8ToUTF16(new_lookup_table.annotations[candidate_index])); | 727 candidate_view->SetRowEnabled(true); |
| 743 candidate_view->SetRowEnabled(true); | 728 candidate_view->SetInfolistIcon(!entry.description_title.empty()); |
| 744 | |
| 745 candidate_view->SetInfolistIcon( | |
| 746 !new_lookup_table.descriptions[candidate_index].title.empty()); | |
| 747 } else { | 729 } else { |
| 748 // Disable the empty row. | 730 // Disable the empty row. |
| 749 candidate_view->SetCandidateText(string16()); | 731 candidate_view->SetCandidateText(string16()); |
| 750 candidate_view->SetAnnotationText(string16()); | 732 candidate_view->SetAnnotationText(string16()); |
| 751 candidate_view->SetRowEnabled(false); | 733 candidate_view->SetRowEnabled(false); |
| 752 candidate_view->SetInfolistIcon(false); | 734 candidate_view->SetInfolistIcon(false); |
| 753 } | 735 } |
| 754 } | 736 } |
| 755 } | 737 } |
| 756 // Update the current lookup table. We'll use lookup_table_ from here. | 738 // Update the current lookup table. We'll use lookup_table_ from here. |
| 757 // Note that SelectCandidateAt() uses lookup_table_. | 739 // Note that SelectCandidateAt() uses lookup_table_. |
| 758 lookup_table_ = new_lookup_table; | 740 lookup_table_.CopyFrom(new_lookup_table); |
| 759 | 741 |
| 760 // Select the current candidate in the page. | 742 // Select the current candidate in the page. |
| 761 const int current_candidate_in_page = | 743 const int current_candidate_in_page = |
| 762 lookup_table_.cursor_absolute_index % lookup_table_.page_size; | 744 lookup_table_.cursor_position() % lookup_table_.page_size(); |
| 763 SelectCandidateAt(current_candidate_in_page); | 745 SelectCandidateAt(current_candidate_in_page); |
| 764 } | 746 } |
| 765 | 747 |
| 766 void CandidateWindowView::MaybeInitializeCandidateViews( | 748 void CandidateWindowView::MaybeInitializeCandidateViews( |
| 767 const InputMethodLookupTable& lookup_table) { | 749 const ibus::IBusLookupTable& lookup_table) { |
| 768 const InputMethodLookupTable::Orientation orientation = | 750 const ibus::IBusLookupTable::Orientation orientation = |
| 769 lookup_table.orientation; | 751 lookup_table.orientation(); |
| 770 const int page_size = lookup_table.page_size; | 752 const int page_size = lookup_table.page_size(); |
| 771 views::View* candidate_area_contents = candidate_area_->contents(); | 753 views::View* candidate_area_contents = candidate_area_->contents(); |
| 772 | 754 |
| 773 // Current column width. | 755 // Current column width. |
| 774 gfx::Size shortcut_column_size(0, 0); | 756 gfx::Size shortcut_column_size(0, 0); |
| 775 gfx::Size candidate_column_size(0,0); | 757 gfx::Size candidate_column_size(0,0); |
| 776 gfx::Size annotation_column_size(0, 0); | 758 gfx::Size annotation_column_size(0, 0); |
| 777 | 759 |
| 778 // If orientation is horizontal, don't need to compute width, | 760 // If orientation is horizontal, don't need to compute width, |
| 779 // because each label is left aligned. | 761 // because each label is left aligned. |
| 780 if (orientation == InputMethodLookupTable::kVertical) { | 762 if (orientation == ibus::IBusLookupTable::VERTICAL) { |
| 781 shortcut_column_size = ComputeShortcutColumnSize(lookup_table); | 763 shortcut_column_size = ComputeShortcutColumnSize(lookup_table); |
| 782 candidate_column_size = ComputeCandidateColumnSize(lookup_table); | 764 candidate_column_size = ComputeCandidateColumnSize(lookup_table); |
| 783 annotation_column_size = ComputeAnnotationColumnSize(lookup_table); | 765 annotation_column_size = ComputeAnnotationColumnSize(lookup_table); |
| 784 } | 766 } |
| 785 | 767 |
| 786 // If the requested number of views matches the number of current views, and | 768 // If the requested number of views matches the number of current views, and |
| 787 // previous and current column width are same, just reuse these. | 769 // previous and current column width are same, just reuse these. |
| 788 // | 770 // |
| 789 // Note that the early exit logic is not only useful for improving | 771 // Note that the early exit logic is not only useful for improving |
| 790 // performance, but also necessary for the horizontal candidate window | 772 // performance, but also necessary for the horizontal candidate window |
| 791 // to be redrawn properly. If we get rid of the logic, the horizontal | 773 // to be redrawn properly. If we get rid of the logic, the horizontal |
| 792 // candidate window won't get redrawn properly for some reason when | 774 // candidate window won't get redrawn properly for some reason when |
| 793 // there is no size change. You can test this by removing "return" here | 775 // there is no size change. You can test this by removing "return" here |
| 794 // and type "ni" with Pinyin input method. | 776 // and type "ni" with Pinyin input method. |
| 795 if (static_cast<int>(candidate_views_.size()) == page_size && | 777 if (static_cast<int>(candidate_views_.size()) == page_size && |
| 796 lookup_table_.orientation == orientation && | 778 lookup_table_.orientation() == orientation && |
| 797 previous_shortcut_column_size_ == shortcut_column_size && | 779 previous_shortcut_column_size_ == shortcut_column_size && |
| 798 previous_candidate_column_size_ == candidate_column_size && | 780 previous_candidate_column_size_ == candidate_column_size && |
| 799 previous_annotation_column_size_ == annotation_column_size) { | 781 previous_annotation_column_size_ == annotation_column_size) { |
| 800 return; | 782 return; |
| 801 } | 783 } |
| 802 | 784 |
| 803 // Update the previous column widths. | 785 // Update the previous column widths. |
| 804 previous_shortcut_column_size_ = shortcut_column_size; | 786 previous_shortcut_column_size_ = shortcut_column_size; |
| 805 previous_candidate_column_size_ = candidate_column_size; | 787 previous_candidate_column_size_ = candidate_column_size; |
| 806 previous_annotation_column_size_ = annotation_column_size; | 788 previous_annotation_column_size_ = annotation_column_size; |
| 807 | 789 |
| 808 // Clear the existing candidate_views if any. | 790 // Clear the existing candidate_views if any. |
| 809 for (size_t i = 0; i < candidate_views_.size(); ++i) { | 791 for (size_t i = 0; i < candidate_views_.size(); ++i) { |
| 810 candidate_area_contents->RemoveChildView(candidate_views_[i]); | 792 candidate_area_contents->RemoveChildView(candidate_views_[i]); |
| 811 // Delete the view after getting out the current message loop iteration. | 793 // Delete the view after getting out the current message loop iteration. |
| 812 MessageLoop::current()->DeleteSoon(FROM_HERE, candidate_views_[i]); | 794 MessageLoop::current()->DeleteSoon(FROM_HERE, candidate_views_[i]); |
| 813 } | 795 } |
| 814 candidate_views_.clear(); | 796 candidate_views_.clear(); |
| 815 | 797 |
| 816 views::GridLayout* layout = new views::GridLayout(candidate_area_contents); | 798 views::GridLayout* layout = new views::GridLayout(candidate_area_contents); |
| 817 // |candidate_area_contents| owns |layout|. | 799 // |candidate_area_contents| owns |layout|. |
| 818 candidate_area_contents->SetLayoutManager(layout); | 800 candidate_area_contents->SetLayoutManager(layout); |
| 819 // Initialize the column set. | 801 // Initialize the column set. |
| 820 views::ColumnSet* column_set = layout->AddColumnSet(0); | 802 views::ColumnSet* column_set = layout->AddColumnSet(0); |
| 821 if (orientation == InputMethodLookupTable::kVertical) { | 803 if (orientation == ibus::IBusLookupTable::VERTICAL) { |
| 822 column_set->AddColumn(views::GridLayout::FILL, | 804 column_set->AddColumn(views::GridLayout::FILL, |
| 823 views::GridLayout::FILL, | 805 views::GridLayout::FILL, |
| 824 0, views::GridLayout::USE_PREF, 0, 0); | 806 0, views::GridLayout::USE_PREF, 0, 0); |
| 825 } else { | 807 } else { |
| 826 for (int i = 0; i < page_size; ++i) { | 808 for (int i = 0; i < page_size; ++i) { |
| 827 column_set->AddColumn(views::GridLayout::FILL, | 809 column_set->AddColumn(views::GridLayout::FILL, |
| 828 views::GridLayout::FILL, | 810 views::GridLayout::FILL, |
| 829 0, views::GridLayout::USE_PREF, 0, 0); | 811 0, views::GridLayout::USE_PREF, 0, 0); |
| 830 } | 812 } |
| 831 } | 813 } |
| 832 | 814 |
| 833 // Set insets so the border of the selected candidate is drawn inside of | 815 // Set insets so the border of the selected candidate is drawn inside of |
| 834 // the border of the main candidate window, but we don't have the inset | 816 // the border of the main candidate window, but we don't have the inset |
| 835 // at the top and the bottom as we have the borders of the header and | 817 // at the top and the bottom as we have the borders of the header and |
| 836 // footer areas. | 818 // footer areas. |
| 837 const gfx::Insets kCandidateAreaInsets(0, 1, 0, 1); | 819 const gfx::Insets kCandidateAreaInsets(0, 1, 0, 1); |
| 838 layout->SetInsets(kCandidateAreaInsets.top(), | 820 layout->SetInsets(kCandidateAreaInsets.top(), |
| 839 kCandidateAreaInsets.left(), | 821 kCandidateAreaInsets.left(), |
| 840 kCandidateAreaInsets.bottom(), | 822 kCandidateAreaInsets.bottom(), |
| 841 kCandidateAreaInsets.right()); | 823 kCandidateAreaInsets.right()); |
| 842 | 824 |
| 843 // Use maximum height for all rows in candidate area. | 825 // Use maximum height for all rows in candidate area. |
| 844 const int kColumnHeight = std::max(shortcut_column_size.height(), | 826 const int kColumnHeight = std::max(shortcut_column_size.height(), |
| 845 std::max(candidate_column_size.height(), | 827 std::max(candidate_column_size.height(), |
| 846 annotation_column_size.height())); | 828 annotation_column_size.height())); |
| 847 | 829 |
| 848 // Add views to the candidate area. | 830 // Add views to the candidate area. |
| 849 if (orientation == InputMethodLookupTable::kHorizontal) { | 831 if (orientation == ibus::IBusLookupTable::HORIZONTAL) { |
| 850 layout->StartRow(0, 0); | 832 layout->StartRow(0, 0); |
| 851 } | 833 } |
| 852 | 834 |
| 853 for (int i = 0; i < page_size; ++i) { | 835 for (int i = 0; i < page_size; ++i) { |
| 854 CandidateView* candidate_row = new CandidateView(this, i, orientation); | 836 CandidateView* candidate_row = new CandidateView(this, i, orientation); |
| 855 candidate_row->Init(shortcut_column_size.width(), | 837 candidate_row->Init(shortcut_column_size.width(), |
| 856 candidate_column_size.width(), | 838 candidate_column_size.width(), |
| 857 annotation_column_size.width(), | 839 annotation_column_size.width(), |
| 858 kColumnHeight); | 840 kColumnHeight); |
| 859 candidate_views_.push_back(candidate_row); | 841 candidate_views_.push_back(candidate_row); |
| 860 if (orientation == InputMethodLookupTable::kVertical) { | 842 if (orientation == ibus::IBusLookupTable::VERTICAL) { |
| 861 layout->StartRow(0, 0); | 843 layout->StartRow(0, 0); |
| 862 } | 844 } |
| 863 // |candidate_row| will be owned by |candidate_area_contents|. | 845 // |candidate_row| will be owned by |candidate_area_contents|. |
| 864 layout->AddView(candidate_row, | 846 layout->AddView(candidate_row, |
| 865 1, // Column span. | 847 1, // Column span. |
| 866 1, // Row span. | 848 1, // Row span. |
| 867 views::GridLayout::CENTER, // Horizontal alignment. | 849 views::GridLayout::CENTER, // Horizontal alignment. |
| 868 views::GridLayout::CENTER, // Vertical alignment. | 850 views::GridLayout::CENTER, // Vertical alignment. |
| 869 -1, // Preferred width, not specified. | 851 -1, // Preferred width, not specified. |
| 870 kColumnHeight); // Preferred height. | 852 kColumnHeight); // Preferred height. |
| 871 } | 853 } |
| 872 | 854 |
| 873 // Compute views size in |layout|. | 855 // Compute views size in |layout|. |
| 874 // If we don't call this function, GetHorizontalOffset() often | 856 // If we don't call this function, GetHorizontalOffset() often |
| 875 // returns invalid value (returns 0), then candidate window | 857 // returns invalid value (returns 0), then candidate window |
| 876 // moves right from the correct position in ResizeAndMoveParentFrame(). | 858 // moves right from the correct position in ResizeAndMoveParentFrame(). |
| 877 // TODO(nhiroki): Figure out why it returns invalid value. | 859 // TODO(nhiroki): Figure out why it returns invalid value. |
| 878 // It seems that the x-position of the candidate labels is not set. | 860 // It seems that the x-position of the candidate labels is not set. |
| 879 layout->Layout(candidate_area_contents); | 861 layout->Layout(candidate_area_contents); |
| 880 } | 862 } |
| 881 | 863 |
| 882 bool CandidateWindowView::IsCandidateWindowOpen() const { | 864 bool CandidateWindowView::IsCandidateWindowOpen() const { |
| 883 return !should_show_at_composition_head_ && | 865 return !should_show_at_composition_head_ && |
| 884 candidate_area_->visible() && candidate_area_->IsShown(); | 866 candidate_area_->visible() && candidate_area_->IsShown(); |
| 885 } | 867 } |
| 886 | 868 |
| 887 void CandidateWindowView::SelectCandidateAt(int index_in_page) { | 869 void CandidateWindowView::SelectCandidateAt(int index_in_page) { |
| 888 const int current_page_index = ComputePageIndex(lookup_table_); | 870 const int current_page_index = ComputePageIndex(lookup_table_); |
| 889 if (current_page_index < 0) { | 871 if (current_page_index < 0) { |
| 890 DVLOG(1) << "Invalid lookup_table: " << lookup_table_.ToString(); | |
| 891 return; | 872 return; |
| 892 } | 873 } |
| 893 | 874 |
| 894 const int cursor_absolute_index = | 875 const int cursor_absolute_index = |
| 895 lookup_table_.page_size * current_page_index + index_in_page; | 876 lookup_table_.page_size() * current_page_index + index_in_page; |
| 896 // Ignore click on out of range views. | 877 // Ignore click on out of range views. |
| 897 if (cursor_absolute_index < 0 || | 878 if (cursor_absolute_index < 0 || |
| 898 cursor_absolute_index >= | 879 cursor_absolute_index >= |
| 899 static_cast<int>(lookup_table_.candidates.size())) { | 880 static_cast<int>(lookup_table_.candidates().size())) { |
| 900 return; | 881 return; |
| 901 } | 882 } |
| 902 | 883 |
| 903 // Unselect the currently selected candidate. | 884 // Unselect the currently selected candidate. |
| 904 candidate_views_[selected_candidate_index_in_page_]->Unselect(); | 885 candidate_views_[selected_candidate_index_in_page_]->Unselect(); |
| 905 // Remember the currently selected candidate index in the current page. | 886 // Remember the currently selected candidate index in the current page. |
| 906 selected_candidate_index_in_page_ = index_in_page; | 887 selected_candidate_index_in_page_ = index_in_page; |
| 907 | 888 |
| 908 // Select the candidate specified by index_in_page. | 889 // Select the candidate specified by index_in_page. |
| 909 candidate_views_[index_in_page]->Select(); | 890 candidate_views_[index_in_page]->Select(); |
| 910 | 891 |
| 911 // Update the cursor indexes in the model. | 892 // Update the cursor indexes in the model. |
| 912 lookup_table_.cursor_absolute_index = cursor_absolute_index; | 893 lookup_table_.set_cursor_position(cursor_absolute_index); |
| 913 } | 894 } |
| 914 | 895 |
| 915 void CandidateWindowView::OnCandidatePressed( | 896 void CandidateWindowView::OnCandidatePressed( |
| 916 const gfx::Point& location) { | 897 const gfx::Point& location) { |
| 917 for (size_t i = 0; i < candidate_views_.size(); ++i) { | 898 for (size_t i = 0; i < candidate_views_.size(); ++i) { |
| 918 gfx::Point converted_location = location; | 899 gfx::Point converted_location = location; |
| 919 views::View::ConvertPointToTarget(this, candidate_views_[i], | 900 views::View::ConvertPointToTarget(this, candidate_views_[i], |
| 920 &converted_location); | 901 &converted_location); |
| 921 if (candidate_views_[i]->HitTestPoint(converted_location)) { | 902 if (candidate_views_[i]->HitTestPoint(converted_location)) { |
| 922 SelectCandidateAt(i); | 903 SelectCandidateAt(i); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 | 965 |
| 985 // Move the window per the cursor location. | 966 // Move the window per the cursor location. |
| 986 // SetBounds() is not cheap. Only call this when it is really changed. | 967 // SetBounds() is not cheap. Only call this when it is really changed. |
| 987 if (frame_bounds != old_bounds) | 968 if (frame_bounds != old_bounds) |
| 988 parent_frame_->SetBounds(frame_bounds); | 969 parent_frame_->SetBounds(frame_bounds); |
| 989 } | 970 } |
| 990 | 971 |
| 991 int CandidateWindowView::GetHorizontalOffset() { | 972 int CandidateWindowView::GetHorizontalOffset() { |
| 992 // Compute the horizontal offset if the lookup table is vertical. | 973 // Compute the horizontal offset if the lookup table is vertical. |
| 993 if (!candidate_views_.empty() && | 974 if (!candidate_views_.empty() && |
| 994 lookup_table_.orientation == InputMethodLookupTable::kVertical) { | 975 lookup_table_.orientation() == ibus::IBusLookupTable::VERTICAL) { |
| 995 return - candidate_views_[0]->GetCandidateLabelPosition().x(); | 976 return - candidate_views_[0]->GetCandidateLabelPosition().x(); |
| 996 } | 977 } |
| 997 return 0; | 978 return 0; |
| 998 } | 979 } |
| 999 | 980 |
| 1000 void CandidateWindowView::VisibilityChanged(View* starting_from, | 981 void CandidateWindowView::VisibilityChanged(View* starting_from, |
| 1001 bool is_visible) { | 982 bool is_visible) { |
| 1002 if (is_visible) { | 983 if (is_visible) { |
| 1003 // If the visibility of candidate window is changed, | 984 // If the visibility of candidate window is changed, |
| 1004 // we should move the frame to the right position. | 985 // we should move the frame to the right position. |
| 1005 ResizeAndMoveParentFrame(); | 986 ResizeAndMoveParentFrame(); |
| 1006 } | 987 } |
| 1007 } | 988 } |
| 1008 | 989 |
| 1009 void CandidateWindowView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 990 void CandidateWindowView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 1010 // If the bounds(size) of candidate window is changed, | 991 // If the bounds(size) of candidate window is changed, |
| 1011 // we should move the frame to the right position. | 992 // we should move the frame to the right position. |
| 1012 View::OnBoundsChanged(previous_bounds); | 993 View::OnBoundsChanged(previous_bounds); |
| 1013 ResizeAndMoveParentFrame(); | 994 ResizeAndMoveParentFrame(); |
| 1014 } | 995 } |
| 1015 | 996 |
| 1016 } // namespace input_method | 997 } // namespace input_method |
| 1017 } // namespace chromeos | 998 } // namespace chromeos |
| OLD | NEW |