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

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: Further renaming 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
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, 0, (position == BOTTOM) ? 1 : 0, 0,
125 GetNativeTheme()->GetSystemColor( 125 GetNativeTheme()->GetSystemColor(
126 ui::NativeTheme::kColorId_MenuBorderColor))); 126 ui::NativeTheme::kColorId_MenuBorderColor)));
127 } 127 }
128 128
129 protected: 129 protected:
130 virtual gfx::Size GetPreferredSize() OVERRIDE { 130 virtual gfx::Size GetPreferredSize() OVERRIDE {
131 gfx::Size size = views::View::GetPreferredSize(); 131 gfx::Size size = views::View::GetPreferredSize();
132 size.SetToMax(gfx::Size(min_width_, 0)); 132 size.SetToMax(gfx::Size(min_width_, 0));
133 return size; 133 return size;
(...skipping 12 matching lines...) Expand all
146 should_show_upper_side_(false), 146 should_show_upper_side_(false),
147 was_candidate_window_open_(false) { 147 was_candidate_window_open_(false) {
148 set_parent_window(parent); 148 set_parent_window(parent);
149 set_margins(gfx::Insets()); 149 set_margins(gfx::Insets());
150 150
151 // Set the background and the border of the view. 151 // Set the background and the border of the view.
152 ui::NativeTheme* theme = GetNativeTheme(); 152 ui::NativeTheme* theme = GetNativeTheme();
153 set_background( 153 set_background(
154 views::Background::CreateSolidBackground(theme->GetSystemColor( 154 views::Background::CreateSolidBackground(theme->GetSystemColor(
155 ui::NativeTheme::kColorId_WindowBackground))); 155 ui::NativeTheme::kColorId_WindowBackground)));
156 set_border(views::Border::CreateSolidBorder( 156 SetBorder(views::Border::CreateSolidBorder(
157 1, theme->GetSystemColor(ui::NativeTheme::kColorId_MenuBorderColor))); 157 1, theme->GetSystemColor(ui::NativeTheme::kColorId_MenuBorderColor)));
158 158
159 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 159 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
160 auxiliary_text_ = new InformationTextArea(gfx::ALIGN_RIGHT, 0); 160 auxiliary_text_ = new InformationTextArea(gfx::ALIGN_RIGHT, 0);
161 preedit_ = new InformationTextArea(gfx::ALIGN_LEFT, kMinPreeditAreaWidth); 161 preedit_ = new InformationTextArea(gfx::ALIGN_LEFT, kMinPreeditAreaWidth);
162 candidate_area_ = new views::View; 162 candidate_area_ = new views::View;
163 auxiliary_text_->SetVisible(false); 163 auxiliary_text_->SetVisible(false);
164 preedit_->SetVisible(false); 164 preedit_->SetVisible(false);
165 candidate_area_->SetVisible(false); 165 candidate_area_->SetVisible(false);
166 preedit_->SetBorder(InformationTextArea::BOTTOM); 166 preedit_->SetBorderFromPosition(InformationTextArea::BOTTOM);
167 if (candidate_window_.orientation() == ui::CandidateWindow::VERTICAL) { 167 if (candidate_window_.orientation() == ui::CandidateWindow::VERTICAL) {
168 AddChildView(preedit_); 168 AddChildView(preedit_);
169 AddChildView(candidate_area_); 169 AddChildView(candidate_area_);
170 AddChildView(auxiliary_text_); 170 AddChildView(auxiliary_text_);
171 auxiliary_text_->SetBorder(InformationTextArea::TOP); 171 auxiliary_text_->SetBorderFromPosition(InformationTextArea::TOP);
172 candidate_area_->SetLayoutManager(new views::BoxLayout( 172 candidate_area_->SetLayoutManager(new views::BoxLayout(
173 views::BoxLayout::kVertical, 0, 0, 0)); 173 views::BoxLayout::kVertical, 0, 0, 0));
174 } else { 174 } else {
175 AddChildView(preedit_); 175 AddChildView(preedit_);
176 AddChildView(auxiliary_text_); 176 AddChildView(auxiliary_text_);
177 AddChildView(candidate_area_); 177 AddChildView(candidate_area_);
178 auxiliary_text_->SetAlignment(gfx::ALIGN_LEFT); 178 auxiliary_text_->SetAlignment(gfx::ALIGN_LEFT);
179 auxiliary_text_->SetBorder(InformationTextArea::BOTTOM); 179 auxiliary_text_->SetBorderFromPosition(InformationTextArea::BOTTOM);
180 candidate_area_->SetLayoutManager(new views::BoxLayout( 180 candidate_area_->SetLayoutManager(new views::BoxLayout(
181 views::BoxLayout::kHorizontal, 0, 0, 0)); 181 views::BoxLayout::kHorizontal, 0, 0, 0));
182 } 182 }
183 } 183 }
184 184
185 CandidateWindowView::~CandidateWindowView() { 185 CandidateWindowView::~CandidateWindowView() {
186 } 186 }
187 187
188 views::Widget* CandidateWindowView::InitWidget() { 188 views::Widget* CandidateWindowView::InitWidget() {
189 views::Widget* widget = BubbleDelegateView::CreateBubble(this); 189 views::Widget* widget = BubbleDelegateView::CreateBubble(this);
190 190
191 views::corewm::SetWindowVisibilityAnimationType( 191 views::corewm::SetWindowVisibilityAnimationType(
192 widget->GetNativeView(), 192 widget->GetNativeView(),
193 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); 193 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
194 194
195 GetBubbleFrameView()->SetBubbleBorder( 195 GetBubbleFrameView()->SetBubbleBorder(scoped_ptr<views::BubbleBorder>(
196 new CandidateWindowBorder(parent_window())); 196 new CandidateWindowBorder(parent_window())));
197 return widget; 197 return widget;
198 } 198 }
199 199
200 void CandidateWindowView::UpdateVisibility() { 200 void CandidateWindowView::UpdateVisibility() {
201 if (candidate_area_->visible() || auxiliary_text_->visible() || 201 if (candidate_area_->visible() || auxiliary_text_->visible() ||
202 preedit_->visible()) { 202 preedit_->visible()) {
203 SizeToContents(); 203 SizeToContents();
204 } else { 204 } else {
205 GetWidget()->Close(); 205 GetWidget()->Close();
206 } 206 }
(...skipping 28 matching lines...) Expand all
235 void CandidateWindowView::UpdateCandidates( 235 void CandidateWindowView::UpdateCandidates(
236 const ui::CandidateWindow& new_candidate_window) { 236 const ui::CandidateWindow& new_candidate_window) {
237 // Updating the candidate views is expensive. We'll skip this if possible. 237 // Updating the candidate views is expensive. We'll skip this if possible.
238 if (!candidate_window_.IsEqual(new_candidate_window)) { 238 if (!candidate_window_.IsEqual(new_candidate_window)) {
239 if (candidate_window_.orientation() != new_candidate_window.orientation()) { 239 if (candidate_window_.orientation() != new_candidate_window.orientation()) {
240 // If the new layout is vertical, the aux text should appear at the 240 // If the new layout is vertical, the aux text should appear at the
241 // bottom. If horizontal, it should appear between preedit and candidates. 241 // bottom. If horizontal, it should appear between preedit and candidates.
242 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) { 242 if (new_candidate_window.orientation() == ui::CandidateWindow::VERTICAL) {
243 ReorderChildView(auxiliary_text_, -1); 243 ReorderChildView(auxiliary_text_, -1);
244 auxiliary_text_->SetAlignment(gfx::ALIGN_RIGHT); 244 auxiliary_text_->SetAlignment(gfx::ALIGN_RIGHT);
245 auxiliary_text_->SetBorder(InformationTextArea::TOP); 245 auxiliary_text_->SetBorderFromPosition(InformationTextArea::TOP);
246 candidate_area_->SetLayoutManager(new views::BoxLayout( 246 candidate_area_->SetLayoutManager(new views::BoxLayout(
247 views::BoxLayout::kVertical, 0, 0, 0)); 247 views::BoxLayout::kVertical, 0, 0, 0));
248 } else { 248 } else {
249 ReorderChildView(auxiliary_text_, 1); 249 ReorderChildView(auxiliary_text_, 1);
250 auxiliary_text_->SetAlignment(gfx::ALIGN_LEFT); 250 auxiliary_text_->SetAlignment(gfx::ALIGN_LEFT);
251 auxiliary_text_->SetBorder(InformationTextArea::BOTTOM); 251 auxiliary_text_->SetBorderFromPosition(InformationTextArea::BOTTOM);
252 candidate_area_->SetLayoutManager(new views::BoxLayout( 252 candidate_area_->SetLayoutManager(new views::BoxLayout(
253 views::BoxLayout::kHorizontal, 0, 0, 0)); 253 views::BoxLayout::kHorizontal, 0, 0, 0));
254 } 254 }
255 } 255 }
256 256
257 // Initialize candidate views if necessary. 257 // Initialize candidate views if necessary.
258 MaybeInitializeCandidateViews(new_candidate_window); 258 MaybeInitializeCandidateViews(new_candidate_window);
259 259
260 should_show_at_composition_head_ 260 should_show_at_composition_head_
261 = new_candidate_window.show_window_at_composition(); 261 = 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) { 394 for (size_t i = 0; i < candidate_views_.size(); ++i) {
395 if (sender == candidate_views_[i]) { 395 if (sender == candidate_views_[i]) {
396 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateCommitted(i)); 396 FOR_EACH_OBSERVER(Observer, observers_, OnCandidateCommitted(i));
397 return; 397 return;
398 } 398 }
399 } 399 }
400 } 400 }
401 401
402 } // namespace ime 402 } // namespace ime
403 } // namespace ash 403 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698