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

Side by Side Diff: ash/ime/candidate_window_view.cc

Issue 145033006: views: Make View::set_border() take a scoped_ptr<>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT Created 6 years, 11 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
« no previous file with comments | « ash/ime/candidate_view.cc ('k') | ash/ime/infolist_window.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ash/ime/candidate_window_view.h" 5 #include "ash/ime/candidate_window_view.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/ime/candidate_view.h" 9 #include "ash/ime/candidate_view.h"
10 #include "ash/ime/candidate_window_constants.h" 10 #include "ash/ime/candidate_window_constants.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 enum BorderPosition { 90 enum BorderPosition {
91 TOP, 91 TOP,
92 BOTTOM 92 BOTTOM
93 }; 93 };
94 94
95 // Specify the alignment and initialize the control. 95 // Specify the alignment and initialize the control.
96 InformationTextArea(gfx::HorizontalAlignment align, int min_width) 96 InformationTextArea(gfx::HorizontalAlignment align, int min_width)
97 : min_width_(min_width) { 97 : min_width_(min_width) {
98 label_ = new views::Label; 98 label_ = new views::Label;
99 label_->SetHorizontalAlignment(align); 99 label_->SetHorizontalAlignment(align);
100 label_->set_border(views::Border::CreateEmptyBorder(2, 2, 2, 4)); 100 label_->SetBorder(views::Border::CreateEmptyBorder(2, 2, 2, 4));
101 101
102 SetLayoutManager(new views::FillLayout()); 102 SetLayoutManager(new views::FillLayout());
103 AddChildView(label_); 103 AddChildView(label_);
104 set_background(views::Background::CreateSolidBackground( 104 set_background(views::Background::CreateSolidBackground(
105 color_utils::AlphaBlend(SK_ColorBLACK, 105 color_utils::AlphaBlend(SK_ColorBLACK,
106 GetNativeTheme()->GetSystemColor( 106 GetNativeTheme()->GetSystemColor(
107 ui::NativeTheme::kColorId_WindowBackground), 107 ui::NativeTheme::kColorId_WindowBackground),
108 0x10))); 108 0x10)));
109 } 109 }
110 110
111 // Sets the text alignment. 111 // Sets the text alignment.
112 void SetAlignment(gfx::HorizontalAlignment alignment) { 112 void SetAlignment(gfx::HorizontalAlignment alignment) {
113 label_->SetHorizontalAlignment(alignment); 113 label_->SetHorizontalAlignment(alignment);
114 } 114 }
115 115
116 // Sets the displayed text. 116 // Sets the displayed text.
117 void SetText(const std::string& utf8_text) { 117 void SetText(const std::string& utf8_text) {
118 label_->SetText(base::UTF8ToUTF16(utf8_text)); 118 label_->SetText(base::UTF8ToUTF16(utf8_text));
119 } 119 }
120 120
121 // Sets the border thickness for top/bottom. 121 // Sets the border thickness for top/bottom.
122 void SetBorder(BorderPosition position) { 122 void SetBorderFromPosition(BorderPosition position) {
123 set_border(views::Border::CreateSolidSidedBorder( 123 SetBorder(views::Border::CreateSolidSidedBorder(
124 (position == TOP) ? 1 : 0, 0, (position == BOTTOM) ? 1 : 0, 0, 124 (position == TOP) ? 1 : 0,
125 0,
126 (position == BOTTOM) ? 1 : 0,
127 0,
125 GetNativeTheme()->GetSystemColor( 128 GetNativeTheme()->GetSystemColor(
126 ui::NativeTheme::kColorId_MenuBorderColor))); 129 ui::NativeTheme::kColorId_MenuBorderColor)));
127 } 130 }
128 131
129 protected: 132 protected:
130 virtual gfx::Size GetPreferredSize() OVERRIDE { 133 virtual gfx::Size GetPreferredSize() OVERRIDE {
131 gfx::Size size = views::View::GetPreferredSize(); 134 gfx::Size size = views::View::GetPreferredSize();
132 size.SetToMax(gfx::Size(min_width_, 0)); 135 size.SetToMax(gfx::Size(min_width_, 0));
133 return size; 136 return size;
134 } 137 }
(...skipping 11 matching lines...) Expand all
146 should_show_upper_side_(false), 149 should_show_upper_side_(false),
147 was_candidate_window_open_(false) { 150 was_candidate_window_open_(false) {
148 set_parent_window(parent); 151 set_parent_window(parent);
149 set_margins(gfx::Insets()); 152 set_margins(gfx::Insets());
150 153
151 // Set the background and the border of the view. 154 // Set the background and the border of the view.
152 ui::NativeTheme* theme = GetNativeTheme(); 155 ui::NativeTheme* theme = GetNativeTheme();
153 set_background( 156 set_background(
154 views::Background::CreateSolidBackground(theme->GetSystemColor( 157 views::Background::CreateSolidBackground(theme->GetSystemColor(
155 ui::NativeTheme::kColorId_WindowBackground))); 158 ui::NativeTheme::kColorId_WindowBackground)));
156 set_border(views::Border::CreateSolidBorder( 159 SetBorder(views::Border::CreateSolidBorder(
157 1, theme->GetSystemColor(ui::NativeTheme::kColorId_MenuBorderColor))); 160 1, theme->GetSystemColor(ui::NativeTheme::kColorId_MenuBorderColor)));
158 161
159 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 162 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
160 auxiliary_text_ = new InformationTextArea(gfx::ALIGN_RIGHT, 0); 163 auxiliary_text_ = new InformationTextArea(gfx::ALIGN_RIGHT, 0);
161 preedit_ = new InformationTextArea(gfx::ALIGN_LEFT, kMinPreeditAreaWidth); 164 preedit_ = new InformationTextArea(gfx::ALIGN_LEFT, kMinPreeditAreaWidth);
162 candidate_area_ = new views::View; 165 candidate_area_ = new views::View;
163 auxiliary_text_->SetVisible(false); 166 auxiliary_text_->SetVisible(false);
164 preedit_->SetVisible(false); 167 preedit_->SetVisible(false);
165 candidate_area_->SetVisible(false); 168 candidate_area_->SetVisible(false);
166 preedit_->SetBorder(InformationTextArea::BOTTOM); 169 preedit_->SetBorderFromPosition(InformationTextArea::BOTTOM);
167 if (candidate_window_.orientation() == ui::CandidateWindow::VERTICAL) { 170 if (candidate_window_.orientation() == ui::CandidateWindow::VERTICAL) {
168 AddChildView(preedit_); 171 AddChildView(preedit_);
169 AddChildView(candidate_area_); 172 AddChildView(candidate_area_);
170 AddChildView(auxiliary_text_); 173 AddChildView(auxiliary_text_);
171 auxiliary_text_->SetBorder(InformationTextArea::TOP); 174 auxiliary_text_->SetBorderFromPosition(InformationTextArea::TOP);
172 candidate_area_->SetLayoutManager(new views::BoxLayout( 175 candidate_area_->SetLayoutManager(new views::BoxLayout(
173 views::BoxLayout::kVertical, 0, 0, 0)); 176 views::BoxLayout::kVertical, 0, 0, 0));
174 } else { 177 } else {
175 AddChildView(preedit_); 178 AddChildView(preedit_);
176 AddChildView(auxiliary_text_); 179 AddChildView(auxiliary_text_);
177 AddChildView(candidate_area_); 180 AddChildView(candidate_area_);
178 auxiliary_text_->SetAlignment(gfx::ALIGN_LEFT); 181 auxiliary_text_->SetAlignment(gfx::ALIGN_LEFT);
179 auxiliary_text_->SetBorder(InformationTextArea::BOTTOM); 182 auxiliary_text_->SetBorderFromPosition(InformationTextArea::BOTTOM);
180 candidate_area_->SetLayoutManager(new views::BoxLayout( 183 candidate_area_->SetLayoutManager(new views::BoxLayout(
181 views::BoxLayout::kHorizontal, 0, 0, 0)); 184 views::BoxLayout::kHorizontal, 0, 0, 0));
182 } 185 }
183 } 186 }
184 187
185 CandidateWindowView::~CandidateWindowView() { 188 CandidateWindowView::~CandidateWindowView() {
186 } 189 }
187 190
188 views::Widget* CandidateWindowView::InitWidget() { 191 views::Widget* CandidateWindowView::InitWidget() {
189 views::Widget* widget = BubbleDelegateView::CreateBubble(this); 192 views::Widget* widget = BubbleDelegateView::CreateBubble(this);
190 193
191 views::corewm::SetWindowVisibilityAnimationType( 194 views::corewm::SetWindowVisibilityAnimationType(
192 widget->GetNativeView(), 195 widget->GetNativeView(),
193 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); 196 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
194 197
195 GetBubbleFrameView()->SetBubbleBorder( 198 GetBubbleFrameView()->SetBubbleBorder(scoped_ptr<views::BubbleBorder>(
196 new CandidateWindowBorder(parent_window())); 199 new CandidateWindowBorder(parent_window())));
197 return widget; 200 return widget;
198 } 201 }
199 202
200 void CandidateWindowView::UpdateVisibility() { 203 void CandidateWindowView::UpdateVisibility() {
201 if (candidate_area_->visible() || auxiliary_text_->visible() || 204 if (candidate_area_->visible() || auxiliary_text_->visible() ||
202 preedit_->visible()) { 205 preedit_->visible()) {
203 SizeToContents(); 206 SizeToContents();
204 } else { 207 } else {
205 GetWidget()->Close(); 208 GetWidget()->Close();
206 } 209 }
(...skipping 28 matching lines...) Expand all
235 void CandidateWindowView::UpdateCandidates( 238 void CandidateWindowView::UpdateCandidates(
236 const ui::CandidateWindow& new_candidate_window) { 239 const ui::CandidateWindow& new_candidate_window) {
237 // Updating the candidate views is expensive. We'll skip this if possible. 240 // Updating the candidate views is expensive. We'll skip this if possible.
238 if (!candidate_window_.IsEqual(new_candidate_window)) { 241 if (!candidate_window_.IsEqual(new_candidate_window)) {
239 if (candidate_window_.orientation() != new_candidate_window.orientation()) { 242 if (candidate_window_.orientation() != new_candidate_window.orientation()) {
240 // If the new layout is vertical, the aux text should appear at the 243 // If the new layout is vertical, the aux text should appear at the
241 // bottom. If horizontal, it should appear between preedit and candidates. 244 // bottom. If horizontal, it should appear between preedit and candidates.
242 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) { 245 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) {
243 ReorderChildView(auxiliary_text_, -1); 246 ReorderChildView(auxiliary_text_, -1);
244 auxiliary_text_->SetAlignment(gfx::ALIGN_RIGHT); 247 auxiliary_text_->SetAlignment(gfx::ALIGN_RIGHT);
245 auxiliary_text_->SetBorder(InformationTextArea::TOP); 248 auxiliary_text_->SetBorderFromPosition(InformationTextArea::TOP);
246 candidate_area_->SetLayoutManager(new views::BoxLayout( 249 candidate_area_->SetLayoutManager(new views::BoxLayout(
247 views::BoxLayout::kVertical, 0, 0, 0)); 250 views::BoxLayout::kVertical, 0, 0, 0));
248 } else { 251 } else {
249 ReorderChildView(auxiliary_text_, 1); 252 ReorderChildView(auxiliary_text_, 1);
250 auxiliary_text_->SetAlignment(gfx::ALIGN_LEFT); 253 auxiliary_text_->SetAlignment(gfx::ALIGN_LEFT);
251 auxiliary_text_->SetBorder(InformationTextArea::BOTTOM); 254 auxiliary_text_->SetBorderFromPosition(InformationTextArea::BOTTOM);
252 candidate_area_->SetLayoutManager(new views::BoxLayout( 255 candidate_area_->SetLayoutManager(new views::BoxLayout(
253 views::BoxLayout::kHorizontal, 0, 0, 0)); 256 views::BoxLayout::kHorizontal, 0, 0, 0));
254 } 257 }
255 } 258 }
256 259
257 // Initialize candidate views if necessary. 260 // Initialize candidate views if necessary.
258 MaybeInitializeCandidateViews(new_candidate_window); 261 MaybeInitializeCandidateViews(new_candidate_window);
259 262
260 should_show_at_composition_head_ 263 should_show_at_composition_head_
261 = new_candidate_window.show_window_at_composition(); 264 = new_candidate_window.show_window_at_composition();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 for (size_t i = 0; i < candidate_views_.size(); ++i) { 397 for (size_t i = 0; i < candidate_views_.size(); ++i) {
395 if (sender == candidate_views_[i]) { 398 if (sender == candidate_views_[i]) {
396 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateCommitted(i)); 399 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateCommitted(i));
397 return; 400 return;
398 } 401 }
399 } 402 }
400 } 403 }
401 404
402 } // namespace ime 405 } // namespace ime
403 } // namespace ash 406 } // namespace ash
OLDNEW
« no previous file with comments | « ash/ime/candidate_view.cc ('k') | ash/ime/infolist_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698