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

Side by Side Diff: ui/views/controls/combobox/combobox.cc

Issue 24883002: Uses and returns the fractional width in text eliding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix round-down problems Created 7 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) 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 4
5 #include "ui/views/controls/combobox/combobox.h" 5 #include "ui/views/controls/combobox/combobox.h"
6 6
7 #include <cmath>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
9 #include "grit/ui_resources.h" 11 #include "grit/ui_resources.h"
10 #include "ui/base/accessibility/accessible_view_state.h" 12 #include "ui/base/accessibility/accessible_view_state.h"
11 #include "ui/base/models/combobox_model.h" 13 #include "ui/base/models/combobox_model.h"
12 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/events/event.h" 15 #include "ui/events/event.h"
14 #include "ui/events/keycodes/keyboard_codes.h" 16 #include "ui/events/keycodes/keyboard_codes.h"
15 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
16 #include "ui/native_theme/native_theme.h" 18 #include "ui/native_theme/native_theme.h"
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 state->value = model_->GetItemAt(selected_index_); 329 state->value = model_->GetItemAt(selected_index_);
328 state->index = selected_index_; 330 state->index = selected_index_;
329 state->count = model_->GetItemCount(); 331 state->count = model_->GetItemCount();
330 } 332 }
331 333
332 void Combobox::OnModelChanged() { 334 void Combobox::OnModelChanged() {
333 ModelChanged(); 335 ModelChanged();
334 } 336 }
335 337
336 void Combobox::UpdateFromModel() { 338 void Combobox::UpdateFromModel() {
337 int max_width = 0; 339 float max_width = 0;
338 const gfx::Font& font = Combobox::GetFont(); 340 const gfx::Font& font = Combobox::GetFont();
339 341
340 MenuItemView* menu = new MenuItemView(this); 342 MenuItemView* menu = new MenuItemView(this);
341 // MenuRunner owns |menu|. 343 // MenuRunner owns |menu|.
342 dropdown_list_menu_runner_.reset(new MenuRunner(menu)); 344 dropdown_list_menu_runner_.reset(new MenuRunner(menu));
343 345
344 int num_items = model()->GetItemCount(); 346 int num_items = model()->GetItemCount();
345 for (int i = 0; i < num_items; ++i) { 347 for (int i = 0; i < num_items; ++i) {
346 if (model()->IsItemSeparatorAt(i)) { 348 if (model()->IsItemSeparatorAt(i)) {
347 menu->AppendSeparator(); 349 menu->AppendSeparator();
348 continue; 350 continue;
349 } 351 }
350 352
351 string16 text = model()->GetItemAt(i); 353 string16 text = model()->GetItemAt(i);
352 354
353 // Inserting the Unicode formatting characters if necessary so that the 355 // Inserting the Unicode formatting characters if necessary so that the
354 // text is displayed correctly in right-to-left UIs. 356 // text is displayed correctly in right-to-left UIs.
355 base::i18n::AdjustStringForLocaleDirection(&text); 357 base::i18n::AdjustStringForLocaleDirection(&text);
356 358
357 menu->AppendMenuItem(i + kFirstMenuItemId, text, MenuItemView::NORMAL); 359 menu->AppendMenuItem(i + kFirstMenuItemId, text, MenuItemView::NORMAL);
358 max_width = std::max(max_width, font.GetStringWidth(text)); 360 max_width = std::max(max_width, font.GetStringWidth(text));
359 } 361 }
360 362
361 content_size_.SetSize(max_width, font.GetHeight()); 363 content_size_.SetSize(std::ceil(max_width), font.GetHeight());
362 } 364 }
363 365
364 void Combobox::AdjustBoundsForRTLUI(gfx::Rect* rect) const { 366 void Combobox::AdjustBoundsForRTLUI(gfx::Rect* rect) const {
365 rect->set_x(GetMirroredXForRect(*rect)); 367 rect->set_x(GetMirroredXForRect(*rect));
366 } 368 }
367 369
368 void Combobox::PaintText(gfx::Canvas* canvas) { 370 void Combobox::PaintText(gfx::Canvas* canvas) {
369 gfx::Insets insets = GetInsets(); 371 gfx::Insets insets = GetInsets();
370 372
371 canvas->Save(); 373 canvas->Save();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } 454 }
453 455
454 void Combobox::OnSelectionChanged() { 456 void Combobox::OnSelectionChanged() {
455 if (listener_) 457 if (listener_)
456 listener_->OnSelectedIndexChanged(this); 458 listener_->OnSelectedIndexChanged(this);
457 NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_VALUE_CHANGED, false); 459 NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_VALUE_CHANGED, false);
458 SchedulePaint(); 460 SchedulePaint();
459 } 461 }
460 462
461 } // namespace views 463 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698