Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/chromeos/input_method/candidate_window.cc

Issue 8221027: Make views::Label and views::Link auto-color themselves to be readable over their background colo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/input_method/candidate_window.h" 5 #include "chrome/browser/chromeos/input_method/candidate_window.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 views::GridLayout::FILL, views::GridLayout::FILL, 112 views::GridLayout::FILL, views::GridLayout::FILL,
113 1, views::GridLayout::USE_PREF, 0, 0); 113 1, views::GridLayout::USE_PREF, 0, 0);
114 layout->StartRow(0, 0); 114 layout->StartRow(0, 0);
115 115
116 // Add the view contents. 116 // Add the view contents.
117 layout->AddView(view); // |view| is owned by |wraper|, not |layout|. 117 layout->AddView(view); // |view| is owned by |wraper|, not |layout|.
118 return wrapper; 118 return wrapper;
119 } 119 }
120 120
121 // Creates shortcut text from the given index and the orientation. 121 // Creates shortcut text from the given index and the orientation.
122 std::wstring CreateShortcutText( 122 string16 CreateShortcutText(int index,
123 int index, 123 InputMethodLookupTable::Orientation orientation) {
124 InputMethodLookupTable::Orientation orientation) {
125 // Choose the character used for the shortcut label. 124 // Choose the character used for the shortcut label.
126 const wchar_t kShortcutCharacters[] = L"1234567890ABCDEF"; 125 const char kShortcutCharacters[] = "1234567890ABCDEF";
127 // The default character should not be used but just in case. 126 // The default character should not be used but just in case.
128 wchar_t shortcut_character = L'?'; 127 char shortcut_character = L'?';
129 // -1 to exclude the null character at the end. 128 // -1 to exclude the null character at the end.
130 if (index < static_cast<int>(arraysize(kShortcutCharacters) - 1)) { 129 if (index < static_cast<int>(arraysize(kShortcutCharacters) - 1))
131 shortcut_character = kShortcutCharacters[index]; 130 shortcut_character = kShortcutCharacters[index];
132 }
133 131
134 std::wstring shortcut_text; 132 std::string shortcut_text(1, shortcut_character);
135 if (orientation == InputMethodLookupTable::kVertical) { 133 if (orientation != InputMethodLookupTable::kVertical)
136 shortcut_text = base::StringPrintf(L"%lc", shortcut_character); 134 shortcut_text += '.';
137 } else { 135 return ASCIIToUTF16(shortcut_text);
138 shortcut_text = base::StringPrintf(L"%lc.", shortcut_character);
139 }
140
141 return shortcut_text;
142 } 136 }
143 137
144 // Creates the shortcut label, and returns it (never returns NULL). 138 // Creates the shortcut label, and returns it (never returns NULL).
145 // The label text is not set in this function. 139 // The label text is not set in this function.
146 views::Label* CreateShortcutLabel( 140 views::Label* CreateShortcutLabel(
147 InputMethodLookupTable::Orientation orientation) { 141 InputMethodLookupTable::Orientation orientation) {
148 // Create the shortcut label. The label will be owned by 142 // Create the shortcut label. The label will be owned by
149 // |wrapped_shortcut_label|, hence it's deleted when 143 // |wrapped_shortcut_label|, hence it's deleted when
150 // |wrapped_shortcut_label| is deleted. 144 // |wrapped_shortcut_label| is deleted.
151 views::Label* shortcut_label = new views::Label; 145 views::Label* shortcut_label = new views::Label;
152 146
153 if (orientation == InputMethodLookupTable::kVertical) { 147 if (orientation == InputMethodLookupTable::kVertical) {
154 shortcut_label->SetFont( 148 shortcut_label->SetFont(
155 shortcut_label->font().DeriveFont(kFontSizeDelta, gfx::Font::BOLD)); 149 shortcut_label->font().DeriveFont(kFontSizeDelta, gfx::Font::BOLD));
156 } else { 150 } else {
157 shortcut_label->SetFont( 151 shortcut_label->SetFont(
158 shortcut_label->font().DeriveFont(kFontSizeDelta)); 152 shortcut_label->font().DeriveFont(kFontSizeDelta));
159 } 153 }
160 // TODO(satorux): Maybe we need to use language specific fonts for 154 // TODO(satorux): Maybe we need to use language specific fonts for
161 // candidate_label, like Chinese font for Chinese input method? 155 // candidate_label, like Chinese font for Chinese input method?
162 shortcut_label->SetColor(kShortcutColor); 156 shortcut_label->SetEnabledColor(kShortcutColor);
157 shortcut_label->SetDisabledColor(kDisabledShortcutColor);
163 158
164 return shortcut_label; 159 return shortcut_label;
165 } 160 }
166 161
167 // Wraps the shortcut label, then decorates wrapped shortcut label 162 // Wraps the shortcut label, then decorates wrapped shortcut label
168 // and returns it (never returns NULL). 163 // and returns it (never returns NULL).
169 // The label text is not set in this function. 164 // The label text is not set in this function.
170 views::View* CreateWrappedShortcutLabel( 165 views::View* CreateWrappedShortcutLabel(
171 views::Label* shortcut_label, 166 views::Label* shortcut_label,
172 InputMethodLookupTable::Orientation orientation) { 167 InputMethodLookupTable::Orientation orientation) {
173 // Wrap it with padding. 168 // Wrap it with padding.
174 const gfx::Insets kVerticalShortcutLabelInsets(1, 6, 1, 6); 169 const gfx::Insets kVerticalShortcutLabelInsets(1, 6, 1, 6);
175 const gfx::Insets kHorizontalShortcutLabelInsets(1, 3, 1, 0); 170 const gfx::Insets kHorizontalShortcutLabelInsets(1, 3, 1, 0);
176 const gfx::Insets insets = 171 const gfx::Insets insets =
177 (orientation == InputMethodLookupTable::kVertical ? 172 (orientation == InputMethodLookupTable::kVertical ?
178 kVerticalShortcutLabelInsets : 173 kVerticalShortcutLabelInsets :
179 kHorizontalShortcutLabelInsets); 174 kHorizontalShortcutLabelInsets);
180 views::View* wrapped_shortcut_label = 175 views::View* wrapped_shortcut_label =
181 WrapWithPadding(shortcut_label, insets); 176 WrapWithPadding(shortcut_label, insets);
182 177
183 // Add decoration based on the orientation. 178 // Add decoration based on the orientation.
184 if (orientation == InputMethodLookupTable::kVertical) { 179 if (orientation == InputMethodLookupTable::kVertical) {
185 // Set the background color. 180 // Set the background color.
186 wrapped_shortcut_label->set_background( 181 wrapped_shortcut_label->set_background(
187 views::Background::CreateSolidBackground( 182 views::Background::CreateSolidBackground(
188 kShortcutBackgroundColor)); 183 kShortcutBackgroundColor));
184 shortcut_label->SetBackgroundColor(
185 wrapped_shortcut_label->background()->get_color());
189 } 186 }
190 187
191 return wrapped_shortcut_label; 188 return wrapped_shortcut_label;
192 } 189 }
193 190
194 // Creates the candidate label, and returns it (never returns NULL). 191 // Creates the candidate label, and returns it (never returns NULL).
195 // The label text is not set in this function. 192 // The label text is not set in this function.
196 views::Label* CreateCandidateLabel( 193 views::Label* CreateCandidateLabel(
197 InputMethodLookupTable::Orientation orientation) { 194 InputMethodLookupTable::Orientation orientation) {
198 views::Label* candidate_label = NULL; 195 views::Label* candidate_label = NULL;
(...skipping 17 matching lines...) Expand all
216 // Creates the annotation label, and return it (never returns NULL). 213 // Creates the annotation label, and return it (never returns NULL).
217 // The label text is not set in this function. 214 // The label text is not set in this function.
218 views::Label* CreateAnnotationLabel( 215 views::Label* CreateAnnotationLabel(
219 InputMethodLookupTable::Orientation orientation) { 216 InputMethodLookupTable::Orientation orientation) {
220 // Create the annotation label. 217 // Create the annotation label.
221 views::Label* annotation_label = new views::Label; 218 views::Label* annotation_label = new views::Label;
222 219
223 // Change the font size and color. 220 // Change the font size and color.
224 annotation_label->SetFont( 221 annotation_label->SetFont(
225 annotation_label->font().DeriveFont(kFontSizeDelta)); 222 annotation_label->font().DeriveFont(kFontSizeDelta));
226 annotation_label->SetColor(kAnnotationColor); 223 annotation_label->SetEnabledColor(kAnnotationColor);
227 annotation_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 224 annotation_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
228 225
229 return annotation_label; 226 return annotation_label;
230 } 227 }
231 228
232 // Computes shortcut column width. 229 // Computes shortcut column width.
233 int ComputeShortcutColumnWidth( 230 int ComputeShortcutColumnWidth(
234 const InputMethodLookupTable& lookup_table) { 231 const InputMethodLookupTable& lookup_table) {
235 int shortcut_column_width = 0; 232 int shortcut_column_width = 0;
236 // Create the shortcut label. The label will be owned by 233 // Create the shortcut label. The label will be owned by
237 // |wrapped_shortcut_label|, hence it's deleted when 234 // |wrapped_shortcut_label|, hence it's deleted when
238 // |wrapped_shortcut_label| is deleted. 235 // |wrapped_shortcut_label| is deleted.
239 views::Label* shortcut_label = CreateShortcutLabel(lookup_table.orientation); 236 views::Label* shortcut_label = CreateShortcutLabel(lookup_table.orientation);
240 scoped_ptr<views::View> wrapped_shortcut_label( 237 scoped_ptr<views::View> wrapped_shortcut_label(
241 CreateWrappedShortcutLabel(shortcut_label, lookup_table.orientation)); 238 CreateWrappedShortcutLabel(shortcut_label, lookup_table.orientation));
242 239
243 // Compute the max width in shortcut labels. 240 // Compute the max width in shortcut labels.
244 // We'll create temporary shortcut labels, and choose the largest width. 241 // We'll create temporary shortcut labels, and choose the largest width.
245 for (int i = 0; i < lookup_table.page_size; ++i) { 242 for (int i = 0; i < lookup_table.page_size; ++i) {
246 shortcut_label->SetText( 243 shortcut_label->SetText(CreateShortcutText(i, lookup_table.orientation));
247 WideToUTF16Hack(CreateShortcutText(i, lookup_table.orientation)));
248 shortcut_column_width = 244 shortcut_column_width =
249 std::max(shortcut_column_width, 245 std::max(shortcut_column_width,
250 wrapped_shortcut_label->GetPreferredSize().width()); 246 wrapped_shortcut_label->GetPreferredSize().width());
251 } 247 }
252 248
253 return shortcut_column_width; 249 return shortcut_column_width;
254 } 250 }
255 251
256 // Computes the page index. For instance, if the page size is 9, and the 252 // Computes the page index. For instance, if the page size is 9, and the
257 // cursor is pointing to 13th candidate, the page index will be 1 (2nd 253 // cursor is pointing to 13th candidate, the page index will be 1 (2nd
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 381
386 const gfx::Insets kInsets(2, 2, 2, 4); 382 const gfx::Insets kInsets(2, 2, 2, 4);
387 views::View* contents = WrapWithPadding(label_, kInsets); 383 views::View* contents = WrapWithPadding(label_, kInsets);
388 SetContents(contents); 384 SetContents(contents);
389 contents->set_border( 385 contents->set_border(
390 views::Border::CreateSolidBorder(1, kFrameColor)); 386 views::Border::CreateSolidBorder(1, kFrameColor));
391 contents->set_background( 387 contents->set_background(
392 views::Background::CreateVerticalGradientBackground( 388 views::Background::CreateVerticalGradientBackground(
393 kFooterTopColor, 389 kFooterTopColor,
394 kFooterBottomColor)); 390 kFooterBottomColor));
391 label_->SetBackgroundColor(contents->background()->get_color());
395 } 392 }
396 393
397 // Set the displayed text. 394 // Set the displayed text.
398 void SetText(const std::string& utf8_text) { 395 void SetText(const std::string& utf8_text) {
399 label_->SetText(UTF8ToUTF16(utf8_text)); 396 label_->SetText(UTF8ToUTF16(utf8_text));
400 } 397 }
401 398
402 protected: 399 protected:
403 virtual gfx::Size GetPreferredSize() OVERRIDE { 400 virtual gfx::Size GetPreferredSize() OVERRIDE {
404 gfx::Size size = HidableArea::GetPreferredSize(); 401 gfx::Size size = HidableArea::GetPreferredSize();
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 int index_in_page, 586 int index_in_page,
590 InputMethodLookupTable::Orientation orientation); 587 InputMethodLookupTable::Orientation orientation);
591 virtual ~CandidateView() {} 588 virtual ~CandidateView() {}
592 // Initializes the candidate view with the given column widths. 589 // Initializes the candidate view with the given column widths.
593 // A width of 0 means that the column is resizable. 590 // A width of 0 means that the column is resizable.
594 void Init(int shortcut_column_width, 591 void Init(int shortcut_column_width,
595 int candidate_column_width, 592 int candidate_column_width,
596 int annotation_column_width); 593 int annotation_column_width);
597 594
598 // Sets candidate text to the given text. 595 // Sets candidate text to the given text.
599 void SetCandidateText(const std::wstring& text); 596 void SetCandidateText(const string16& text);
600 597
601 // Sets shortcut text to the given text. 598 // Sets shortcut text to the given text.
602 void SetShortcutText(const std::wstring& text); 599 void SetShortcutText(const string16& text);
603 600
604 // Sets annotation text to the given text. 601 // Sets annotation text to the given text.
605 void SetAnnotationText(const std::wstring& text); 602 void SetAnnotationText(const string16& text);
606 603
607 // Sets infolist icon. 604 // Sets infolist icon.
608 void SetInfolistIcon(bool enable); 605 void SetInfolistIcon(bool enable);
609 606
610 // Selects the candidate row. Changes the appearance to make it look 607 // Selects the candidate row. Changes the appearance to make it look
611 // like a selected candidate. 608 // like a selected candidate.
612 void Select(); 609 void Select();
613 610
614 // Unselects the candidate row. Changes the appearance to make it look 611 // Unselects the candidate row. Changes the appearance to make it look
615 // like an unselected candidate. 612 // like an unselected candidate.
616 void Unselect(); 613 void Unselect();
617 614
618 // Enables or disables the candidate row based on |enabled|. Changes the 615 // Enables or disables the candidate row based on |enabled|. Changes the
619 // appearance to make it look like unclickable area. 616 // appearance to make it look like unclickable area.
620 void SetRowEnabled(bool enabled); 617 void SetRowEnabled(bool enabled);
621 618
622 // Returns the relative position of the candidate label. 619 // Returns the relative position of the candidate label.
623 gfx::Point GetCandidateLabelPosition() const; 620 gfx::Point GetCandidateLabelPosition() const;
624 621
625 private: 622 private:
626 // Overridden from View: 623 // Overridden from View:
627 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; 624 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE;
628 625
626 // Notifies labels of their new background colors. Called whenever the view's
627 // background color changes.
628 void UpdateLabelBackgroundColors();
629
629 // Zero-origin index in the current page. 630 // Zero-origin index in the current page.
630 int index_in_page_; 631 int index_in_page_;
631 632
632 // The orientation of the candidate view. 633 // The orientation of the candidate view.
633 InputMethodLookupTable::Orientation orientation_; 634 InputMethodLookupTable::Orientation orientation_;
634 635
635 // The parent candidate window that contains this view. 636 // The parent candidate window that contains this view.
636 CandidateWindowView* parent_candidate_window_; 637 CandidateWindowView* parent_candidate_window_;
637 638
638 // Views created in the class will be part of tree of |this|, so these 639 // Views created in the class will be part of tree of |this|, so these
639 // child views will be deleted when |this| is deleted. 640 // child views will be deleted when |this| is deleted.
640 641
641 // The shortcut label renders shortcut numbers like 1, 2, and 3. 642 // The shortcut label renders shortcut numbers like 1, 2, and 3.
642 views::Label* shortcut_label_; 643 views::Label* shortcut_label_;
643 // The candidate label renders candidates. 644 // The candidate label renders candidates.
644 views::Label* candidate_label_; 645 views::Label* candidate_label_;
645 // The annotation label renders annotations. 646 // The annotation label renders annotations.
646 views::Label* annotation_label_; 647 views::Label* annotation_label_;
647 648
648 // The infolist icon. 649 // The infolist icon.
649 views::Label* infolist_label_; 650 views::Label* infolist_label_;
650 bool infolist_icon_enabled_; 651 bool infolist_icon_enabled_;
651 }; 652 };
652 653
653 class InfolistView; 654 class InfolistView;
654 655
655 // InfolistWindowView is the main container of the infolist window UI. 656 // InfolistWindowView is the main container of the infolist window UI.
656 class InfolistWindowView : public views::View { 657 class InfolistWindowView : public views::View {
657 public: 658 public:
658 InfolistWindowView( 659 InfolistWindowView(views::Widget* parent_frame,
659 views::Widget* parent_frame, views::Widget* candidate_window_frame); 660 views::Widget* candidate_window_frame);
660 virtual ~InfolistWindowView(); 661 virtual ~InfolistWindowView();
661 void Init(); 662 void Init();
662 void Show(); 663 void Show();
663 void DelayShow(unsigned int milliseconds); 664 void DelayShow(unsigned int milliseconds);
664 void Hide(); 665 void Hide();
665 void DelayHide(unsigned int milliseconds); 666 void DelayHide(unsigned int milliseconds);
666 void UpdateCandidates(const InputMethodLookupTable& lookup_table); 667 void UpdateCandidates(const InputMethodLookupTable& lookup_table);
667 668
668 void ResizeAndMoveParentFrame(); 669 void ResizeAndMoveParentFrame();
669 670
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 716
716 // Selects the infolist row. Changes the appearance to make it look 717 // Selects the infolist row. Changes the appearance to make it look
717 // like a selected candidate. 718 // like a selected candidate.
718 void Select(); 719 void Select();
719 720
720 // Unselects the infolist row. Changes the appearance to make it look 721 // Unselects the infolist row. Changes the appearance to make it look
721 // like an unselected candidate. 722 // like an unselected candidate.
722 void Unselect(); 723 void Unselect();
723 724
724 private: 725 private:
726 // Notifies labels of their new background colors. Called whenever the view's
727 // background color changes.
728 void UpdateLabelBackgroundColors();
729
725 // The parent candidate window that contains this view. 730 // The parent candidate window that contains this view.
726 InfolistWindowView* parent_infolist_window_; 731 InfolistWindowView* parent_infolist_window_;
727 732
728 // Views created in the class will be part of tree of |this|, so these 733 // Views created in the class will be part of tree of |this|, so these
729 // child views will be deleted when |this| is deleted. 734 // child views will be deleted when |this| is deleted.
730 735
731 // The title label. 736 // The title label.
732 views::Label* title_label_; 737 views::Label* title_label_;
733 // The description label. 738 // The description label.
734 views::Label* description_label_; 739 views::Label* description_label_;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 layout->StartRow(0, 0); 859 layout->StartRow(0, 0);
855 // |wrapped_shortcut_label|, |candidate_label_|, and |annotation_label_| 860 // |wrapped_shortcut_label|, |candidate_label_|, and |annotation_label_|
856 // will be owned by |this|. 861 // will be owned by |this|.
857 layout->AddView(wrapped_shortcut_label); 862 layout->AddView(wrapped_shortcut_label);
858 layout->AddView(candidate_label_); 863 layout->AddView(candidate_label_);
859 layout->AddView(annotation_label_); 864 layout->AddView(annotation_label_);
860 if (orientation_ == InputMethodLookupTable::kVertical) { 865 if (orientation_ == InputMethodLookupTable::kVertical) {
861 layout->AddView(WrapWithPadding(infolist_label_, 866 layout->AddView(WrapWithPadding(infolist_label_,
862 gfx::Insets(2, 0, 2, 0))); 867 gfx::Insets(2, 0, 2, 0)));
863 } 868 }
869 UpdateLabelBackgroundColors();
864 } 870 }
865 871
866 void CandidateView::SetCandidateText(const std::wstring& text) { 872 void CandidateView::SetCandidateText(const string16& text) {
867 candidate_label_->SetText(WideToUTF16Hack(text)); 873 candidate_label_->SetText(text);
868 } 874 }
869 875
870 void CandidateView::SetShortcutText(const std::wstring& text) { 876 void CandidateView::SetShortcutText(const string16& text) {
871 shortcut_label_->SetText(WideToUTF16Hack(text)); 877 shortcut_label_->SetText(text);
872 } 878 }
873 879
874 void CandidateView::SetAnnotationText(const std::wstring& text) { 880 void CandidateView::SetAnnotationText(const string16& text) {
875 annotation_label_->SetText(WideToUTF16Hack(text)); 881 annotation_label_->SetText(text);
876 } 882 }
877 883
878 void CandidateView::SetInfolistIcon(bool enable) { 884 void CandidateView::SetInfolistIcon(bool enable) {
879 if (!infolist_label_) { 885 if (!infolist_label_ || (infolist_icon_enabled_ == enable))
880 return; 886 return;
881 }
882 if (enable) {
883 infolist_label_->set_background(
884 views::Background::CreateSolidBackground(kSelectedRowFrameColor));
885 } else {
886 infolist_label_->set_background(NULL);
887 }
888 if (infolist_icon_enabled_ != enable) {
889 SchedulePaint();
890 }
891 infolist_icon_enabled_ = enable; 887 infolist_icon_enabled_ = enable;
888 infolist_label_->set_background(enable ?
889 views::Background::CreateSolidBackground(kSelectedRowFrameColor) : NULL);
890 UpdateLabelBackgroundColors();
891 SchedulePaint();
892 } 892 }
893 893
894 void CandidateView::Select() { 894 void CandidateView::Select() {
895 set_background( 895 set_background(
896 views::Background::CreateSolidBackground(kSelectedRowBackgroundColor)); 896 views::Background::CreateSolidBackground(kSelectedRowBackgroundColor));
897 set_border(views::Border::CreateSolidBorder(1, kSelectedRowFrameColor)); 897 set_border(views::Border::CreateSolidBorder(1, kSelectedRowFrameColor));
898 UpdateLabelBackgroundColors();
898 // Need to call SchedulePaint() for background and border color changes. 899 // Need to call SchedulePaint() for background and border color changes.
899 SchedulePaint(); 900 SchedulePaint();
900 } 901 }
901 902
902 void CandidateView::Unselect() { 903 void CandidateView::Unselect() {
903 set_background(NULL); 904 set_background(NULL);
904 set_border(NULL); 905 set_border(NULL);
906 UpdateLabelBackgroundColors();
905 SchedulePaint(); // See comments at Select(). 907 SchedulePaint(); // See comments at Select().
906 } 908 }
907 909
908 void CandidateView::SetRowEnabled(bool enabled) { 910 void CandidateView::SetRowEnabled(bool enabled) {
909 shortcut_label_->SetColor( 911 shortcut_label_->SetEnabled(enabled);
910 enabled ? kShortcutColor : kDisabledShortcutColor);
911 } 912 }
912 913
913 gfx::Point CandidateView::GetCandidateLabelPosition() const { 914 gfx::Point CandidateView::GetCandidateLabelPosition() const {
914 return candidate_label_->GetMirroredPosition(); 915 return candidate_label_->GetMirroredPosition();
915 } 916 }
916 917
917 bool CandidateView::OnMousePressed(const views::MouseEvent& event) { 918 bool CandidateView::OnMousePressed(const views::MouseEvent& event) {
918 // TODO(kinaba): investigate a way to delay the commit until OnMouseReleased. 919 // TODO(kinaba): investigate a way to delay the commit until OnMouseReleased.
919 // Mouse-down selection is a temporally workaround for crosbug.com/11423. 920 // Mouse-down selection is a temporally workaround for crosbug.com/11423.
920 // 921 //
(...skipping 29 matching lines...) Expand all
950 // when a popup window gets hidden. http://crosbug.com/11422 951 // when a popup window gets hidden. http://crosbug.com/11422
951 952
952 gfx::Point location_in_candidate_window = event.location(); 953 gfx::Point location_in_candidate_window = event.location();
953 views::View::ConvertPointToView(this, parent_candidate_window_, 954 views::View::ConvertPointToView(this, parent_candidate_window_,
954 &location_in_candidate_window); 955 &location_in_candidate_window);
955 parent_candidate_window_->OnCandidatePressed(location_in_candidate_window); 956 parent_candidate_window_->OnCandidatePressed(location_in_candidate_window);
956 parent_candidate_window_->CommitCandidate(); 957 parent_candidate_window_->CommitCandidate();
957 return false; 958 return false;
958 } 959 }
959 960
960 CandidateWindowView::CandidateWindowView( 961 void CandidateView::UpdateLabelBackgroundColors() {
961 views::Widget* parent_frame) 962 SkColor color = background() ?
963 background()->get_color() : kDefaultBackgroundColor;
964 if (orientation_ != InputMethodLookupTable::kVertical)
965 shortcut_label_->SetBackgroundColor(color);
966 candidate_label_->SetBackgroundColor(color);
967 annotation_label_->SetBackgroundColor(color);
968 if (infolist_label_) {
969 infolist_label_->SetBackgroundColor(infolist_label_->background() ?
970 infolist_label_->background()->get_color() : color);
971 }
972 }
973
974 CandidateWindowView::CandidateWindowView(views::Widget* parent_frame)
962 : selected_candidate_index_in_page_(0), 975 : selected_candidate_index_in_page_(0),
963 parent_frame_(parent_frame), 976 parent_frame_(parent_frame),
964 preedit_area_(NULL), 977 preedit_area_(NULL),
965 header_area_(NULL), 978 header_area_(NULL),
966 candidate_area_(NULL), 979 candidate_area_(NULL),
967 footer_area_(NULL), 980 footer_area_(NULL),
968 previous_shortcut_column_width_(0), 981 previous_shortcut_column_width_(0),
969 previous_candidate_column_width_(0), 982 previous_candidate_column_width_(0),
970 previous_annotation_column_width_(0) { 983 previous_annotation_column_width_(0) {
971 } 984 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 } 1111 }
1099 1112
1100 // Update the candidates in the current page. 1113 // Update the candidates in the current page.
1101 const size_t start_from = current_page_index * new_lookup_table.page_size; 1114 const size_t start_from = current_page_index * new_lookup_table.page_size;
1102 1115
1103 // In some cases, engines send empty shortcut labels. For instance, 1116 // In some cases, engines send empty shortcut labels. For instance,
1104 // ibus-mozc sends empty labels when they show suggestions. In this 1117 // ibus-mozc sends empty labels when they show suggestions. In this
1105 // case, we should not show shortcut labels. 1118 // case, we should not show shortcut labels.
1106 const bool no_shortcut_mode = 1119 const bool no_shortcut_mode =
1107 (start_from < new_lookup_table.labels.size() && 1120 (start_from < new_lookup_table.labels.size() &&
1108 new_lookup_table.labels[start_from] == ""); 1121 new_lookup_table.labels[start_from].empty());
1109 for (size_t i = 0; i < candidate_views_.size(); ++i) { 1122 for (size_t i = 0; i < candidate_views_.size(); ++i) {
1110 const size_t index_in_page = i; 1123 const size_t index_in_page = i;
1111 const size_t candidate_index = start_from + index_in_page; 1124 const size_t candidate_index = start_from + index_in_page;
1112 CandidateView* candidate_view = candidate_views_[index_in_page]; 1125 CandidateView* candidate_view = candidate_views_[index_in_page];
1113 // Set the shortcut text. 1126 // Set the shortcut text.
1114 if (no_shortcut_mode) { 1127 if (no_shortcut_mode) {
1115 candidate_view->SetShortcutText(L""); 1128 candidate_view->SetShortcutText(string16());
1116 } else { 1129 } else {
1117 // At this moment, we don't use labels sent from engines for UX 1130 // At this moment, we don't use labels sent from engines for UX
1118 // reasons. First, we want to show shortcut labels in empty rows 1131 // reasons. First, we want to show shortcut labels in empty rows
1119 // (ex. show 6, 7, 8, ... in empty rows when the number of 1132 // (ex. show 6, 7, 8, ... in empty rows when the number of
1120 // candidates is 5). Second, we want to add a period after each 1133 // candidates is 5). Second, we want to add a period after each
1121 // shortcut label when the candidate window is horizontal. 1134 // shortcut label when the candidate window is horizontal.
1122 candidate_view->SetShortcutText( 1135 candidate_view->SetShortcutText(
1123 CreateShortcutText(i, new_lookup_table.orientation)); 1136 CreateShortcutText(i, new_lookup_table.orientation));
1124 } 1137 }
1125 // Set the candidate text. 1138 // Set the candidate text.
1126 if (candidate_index < new_lookup_table.candidates.size() && 1139 if (candidate_index < new_lookup_table.candidates.size() &&
1127 candidate_index < new_lookup_table.annotations.size()) { 1140 candidate_index < new_lookup_table.annotations.size()) {
1128 candidate_view->SetCandidateText( 1141 candidate_view->SetCandidateText(
1129 UTF8ToWide(new_lookup_table.candidates[candidate_index])); 1142 UTF8ToUTF16(new_lookup_table.candidates[candidate_index]));
1130 candidate_view->SetAnnotationText( 1143 candidate_view->SetAnnotationText(
1131 UTF8ToWide(new_lookup_table.annotations[candidate_index])); 1144 UTF8ToUTF16(new_lookup_table.annotations[candidate_index]));
1132 candidate_view->SetRowEnabled(true); 1145 candidate_view->SetRowEnabled(true);
1133 1146
1134 if ((new_lookup_table.mozc_candidates.candidate_size() > 1147 if ((new_lookup_table.mozc_candidates.candidate_size() >
1135 static_cast<int>(i)) && 1148 static_cast<int>(i)) &&
1136 (new_lookup_table.mozc_candidates. 1149 (new_lookup_table.mozc_candidates.
1137 candidate(i).has_information_id())) { 1150 candidate(i).has_information_id())) {
1138 candidate_view->SetInfolistIcon(true); 1151 candidate_view->SetInfolistIcon(true);
1139 } else { 1152 } else {
1140 candidate_view->SetInfolistIcon(false); 1153 candidate_view->SetInfolistIcon(false);
1141 } 1154 }
1142 } else { 1155 } else {
1143 // Disable the empty row. 1156 // Disable the empty row.
1144 candidate_view->SetCandidateText(L""); 1157 candidate_view->SetCandidateText(string16());
1145 candidate_view->SetAnnotationText(L""); 1158 candidate_view->SetAnnotationText(string16());
1146 candidate_view->SetRowEnabled(false); 1159 candidate_view->SetRowEnabled(false);
1147 candidate_view->SetInfolistIcon(false); 1160 candidate_view->SetInfolistIcon(false);
1148 } 1161 }
1149 } 1162 }
1150 } 1163 }
1151 // Update the current lookup table. We'll use lookup_table_ from here. 1164 // Update the current lookup table. We'll use lookup_table_ from here.
1152 // Note that SelectCandidateAt() uses lookup_table_. 1165 // Note that SelectCandidateAt() uses lookup_table_.
1153 lookup_table_ = new_lookup_table; 1166 lookup_table_ = new_lookup_table;
1154 1167
1155 // Select the current candidate in the page. 1168 // Select the current candidate in the page.
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 1418
1406 // Initialize the column set with three columns. 1419 // Initialize the column set with three columns.
1407 views::ColumnSet* column_set = layout->AddColumnSet(0); 1420 views::ColumnSet* column_set = layout->AddColumnSet(0);
1408 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1421 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
1409 0, views::GridLayout::FIXED, 200, 0); 1422 0, views::GridLayout::FIXED, 200, 0);
1410 1423
1411 layout->StartRow(0, 0); 1424 layout->StartRow(0, 0);
1412 layout->AddView(wrapped_title_label); 1425 layout->AddView(wrapped_title_label);
1413 layout->StartRow(0, 0); 1426 layout->StartRow(0, 0);
1414 layout->AddView(wrapped_description_label); 1427 layout->AddView(wrapped_description_label);
1428 UpdateLabelBackgroundColors();
1415 } 1429 }
1416 1430
1417 1431
1418 void InfolistView::SetTitleText(const std::wstring& text) { 1432 void InfolistView::SetTitleText(const std::wstring& text) {
1419 title_label_->SetText(WideToUTF16Hack(text)); 1433 title_label_->SetText(WideToUTF16Hack(text));
1420 } 1434 }
1421 1435
1422 void InfolistView::SetDescriptionText(const std::wstring& text) { 1436 void InfolistView::SetDescriptionText(const std::wstring& text) {
1423 description_label_->SetText(WideToUTF16Hack(text)); 1437 description_label_->SetText(WideToUTF16Hack(text));
1424 } 1438 }
1425 1439
1426 void InfolistView::Select() { 1440 void InfolistView::Select() {
1427 set_background( 1441 set_background(views::Background::CreateSolidBackground(
1428 views::Background::CreateSolidBackground( 1442 kSelectedInfolistRowBackgroundColor));
1429 kSelectedInfolistRowBackgroundColor));
1430 set_border( 1443 set_border(
1431 views::Border::CreateSolidBorder(1, kSelectedInfolistRowFrameColor)); 1444 views::Border::CreateSolidBorder(1, kSelectedInfolistRowFrameColor));
1445 UpdateLabelBackgroundColors();
1432 // Need to call SchedulePaint() for background and border color changes. 1446 // Need to call SchedulePaint() for background and border color changes.
1433 SchedulePaint(); 1447 SchedulePaint();
1434 } 1448 }
1435 1449
1436 void InfolistView::Unselect() { 1450 void InfolistView::Unselect() {
1437 set_background(NULL); 1451 set_background(NULL);
1438 set_border(NULL); 1452 set_border(NULL);
1453 UpdateLabelBackgroundColors();
1439 SchedulePaint(); // See comments at Select(). 1454 SchedulePaint(); // See comments at Select().
1440 } 1455 }
1441 1456
1442 InfolistWindowView::InfolistWindowView( 1457 void InfolistView::UpdateLabelBackgroundColors() {
1443 views::Widget* parent_frame, views::Widget* candidate_window_frame) 1458 SkColor color = background() ?
1459 background()->get_color() : kDefaultBackgroundColor;
1460 title_label_->SetBackgroundColor(color);
1461 description_label_->SetBackgroundColor(color);
1462 }
1463
1464 InfolistWindowView::InfolistWindowView(views::Widget* parent_frame,
1465 views::Widget* candidate_window_frame)
1444 : parent_frame_(parent_frame), 1466 : parent_frame_(parent_frame),
1445 candidate_window_frame_(candidate_window_frame), 1467 candidate_window_frame_(candidate_window_frame),
1446 infolist_area_(NULL), 1468 infolist_area_(NULL),
1447 visible_(false) { 1469 visible_(false) {
1448 } 1470 }
1449 1471
1450 InfolistWindowView::~InfolistWindowView() { 1472 InfolistWindowView::~InfolistWindowView() {
1451 if (infolist_area_ != NULL) { 1473 if (infolist_area_ != NULL) {
1452 infolist_area_->RemoveAllChildViews(false); 1474 infolist_area_->RemoveAllChildViews(false);
1453 } 1475 }
(...skipping 23 matching lines...) Expand all
1477 views::Label* caption_label = NULL; 1499 views::Label* caption_label = NULL;
1478 caption_label = new views::Label; 1500 caption_label = new views::Label;
1479 caption_label->SetFont(caption_label->font().DeriveFont(kFontSizeDelta - 2)); 1501 caption_label->SetFont(caption_label->font().DeriveFont(kFontSizeDelta - 2));
1480 caption_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 1502 caption_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
1481 caption_label->SetText( 1503 caption_label->SetText(
1482 l10n_util::GetStringUTF16(IDS_INPUT_METHOD_INFOLIST_WINDOW_TITLE)); 1504 l10n_util::GetStringUTF16(IDS_INPUT_METHOD_INFOLIST_WINDOW_TITLE));
1483 views::View* wrapped_caption_label = 1505 views::View* wrapped_caption_label =
1484 WrapWithPadding(caption_label, gfx::Insets(2, 2, 2, 2)); 1506 WrapWithPadding(caption_label, gfx::Insets(2, 2, 2, 2));
1485 wrapped_caption_label->set_background( 1507 wrapped_caption_label->set_background(
1486 views::Background::CreateSolidBackground(kInfolistTitleBackgroundColor)); 1508 views::Background::CreateSolidBackground(kInfolistTitleBackgroundColor));
1509 caption_label->SetBackgroundColor(
1510 wrapped_caption_label->background()->get_color());
1487 layout->AddView(wrapped_caption_label); 1511 layout->AddView(wrapped_caption_label);
1488 1512
1489 layout->StartRow(0, 0); 1513 layout->StartRow(0, 0);
1490 layout->AddView(infolist_area_); // |infolist_area_| is owned by |this|. 1514 layout->AddView(infolist_area_); // |infolist_area_| is owned by |this|.
1491 } 1515 }
1492 1516
1493 void InfolistWindowView::Hide() { 1517 void InfolistWindowView::Hide() {
1494 visible_ = false; 1518 visible_ = false;
1495 show_hide_timer_.Stop(); 1519 show_hide_timer_.Stop();
1496 parent_frame_->Hide(); 1520 parent_frame_->Hide();
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1797 CandidateWindowController::~CandidateWindowController() { 1821 CandidateWindowController::~CandidateWindowController() {
1798 delete impl_; 1822 delete impl_;
1799 } 1823 }
1800 1824
1801 bool CandidateWindowController::Init() { 1825 bool CandidateWindowController::Init() {
1802 return impl_->Init(); 1826 return impl_->Init();
1803 } 1827 }
1804 1828
1805 } // namespace input_method 1829 } // namespace input_method
1806 } // namespace chromeos 1830 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/frame/panel_controller.cc ('k') | chrome/browser/chromeos/login/background_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698