Commit f1bddb1f authored by tfarina@chromium.org's avatar tfarina@chromium.org

views: Refactor the way we get the combo box font.

R=sky@chromium.org

Review URL: https://chromiumcodereview.appspot.com/9839034

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128915 0039d316-1c4b-4281-b951-d872f2087c98
parent 10b6c133
......@@ -9,6 +9,7 @@
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/models/combobox_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/controls/combobox/combobox_listener.h"
#include "ui/views/controls/native/native_view_host.h"
#include "ui/views/widget/widget.h"
......@@ -32,6 +33,12 @@ Combobox::Combobox(ui::ComboboxModel* model)
Combobox::~Combobox() {
}
// static
const gfx::Font& Combobox::GetFont() {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
return rb.GetFont(ui::ResourceBundle::BaseFont);
}
void Combobox::ModelChanged() {
selected_item_ = std::min(0, model_->GetItemCount());
if (native_wrapper_)
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -12,6 +12,10 @@
#include "ui/views/controls/combobox/native_combobox_wrapper.h"
#include "ui/views/view.h"
namespace gfx {
class Font;
}
namespace ui {
class ComboboxModel;
}
......@@ -30,6 +34,8 @@ class VIEWS_EXPORT Combobox : public View {
explicit Combobox(ui::ComboboxModel* model);
virtual ~Combobox();
static const gfx::Font& GetFont();
// Register |listener| for item change events.
void set_listener(ComboboxListener* listener) {
listener_ = listener;
......
......@@ -160,7 +160,7 @@ void NativeComboboxViews::OnBlur() {
void NativeComboboxViews::UpdateFromModel() {
int max_width = 0;
const gfx::Font &font = GetFont();
const gfx::Font& font = Combobox::GetFont();
MenuItemView* menu = new MenuItemView(this);
// MenuRunner owns |menu|.
......@@ -268,11 +268,6 @@ bool NativeComboboxViews::GetAccelerator(int id, ui::Accelerator* accel) {
/////////////////////////////////////////////////////////////////
// NativeComboboxViews private methods:
const gfx::Font& NativeComboboxViews::GetFont() const {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
return rb.GetFont(ResourceBundle::BaseFont);
}
void NativeComboboxViews::AdjustBoundsForRTLUI(gfx::Rect* rect) const {
rect->set_x(GetMirroredXForRect(*rect));
}
......@@ -296,7 +291,7 @@ void NativeComboboxViews::PaintText(gfx::Canvas* canvas) {
int disclosure_arrow_offset = width() - disclosure_arrow_->width()
- kDisclosureArrowLeftPadding - kDisclosureArrowRightPadding;
const gfx::Font& font = GetFont();
const gfx::Font& font = Combobox::GetFont();
int text_width = font.GetStringWidth(text);
if ((text_width + insets.width()) > disclosure_arrow_offset)
text_width = disclosure_arrow_offset - insets.width();
......
......@@ -17,7 +17,6 @@ class Font;
namespace views {
class KeyEvent;
class FocusableBorder;
class MenuRunner;
......@@ -27,6 +26,8 @@ class NativeComboboxViews : public views::View,
public NativeComboboxWrapper,
public views::MenuDelegate {
public:
static const char kViewClassName[];
explicit NativeComboboxViews(Combobox* parent);
virtual ~NativeComboboxViews();
......@@ -60,13 +61,7 @@ class NativeComboboxViews : public views::View,
virtual void ExecuteCommand(int id) OVERRIDE;
virtual bool GetAccelerator(int id, ui::Accelerator* accelerator) OVERRIDE;
// class name of internal
static const char kViewClassName[];
private:
// Returns the Combobox's font.
const gfx::Font& GetFont() const;
// Given bounds within our View, this helper routine mirrors the bounds if
// necessary.
void AdjustBoundsForRTLUI(gfx::Rect* rect) const;
......
......@@ -15,14 +15,18 @@
#include "ui/views/controls/combobox/native_combobox_views.h"
#include "ui/views/widget/widget.h"
namespace views {
namespace {
// Limit how small a combobox can be.
static const int kMinComboboxWidth = 148;
const int kMinComboboxWidth = 148;
// Add a couple extra pixels to the widths of comboboxes and combobox
// dropdowns so that text isn't too crowded.
static const int kComboboxExtraPaddingX = 6;
const int kComboboxExtraPaddingX = 6;
} // namespace
namespace views {
////////////////////////////////////////////////////////////////////////////////
// NativeComboboxWin, public:
......@@ -44,8 +48,7 @@ NativeComboboxWin::~NativeComboboxWin() {
void NativeComboboxWin::UpdateFromModel() {
SendMessage(native_view(), CB_RESETCONTENT, 0, 0);
gfx::Font font = ResourceBundle::GetSharedInstance().GetFont(
ResourceBundle::BaseFont);
const gfx::Font& font = Combobox::GetFont();
int max_width = 0;
int num_items = combobox_->model()->GetItemCount();
for (int i = 0; i < num_items; ++i) {
......@@ -194,8 +197,7 @@ void NativeComboboxWin::NativeControlCreated(HWND native_control) {
// NativeComboboxWin, private:
void NativeComboboxWin::UpdateFont() {
HFONT font = ResourceBundle::GetSharedInstance().
GetFont(ResourceBundle::BaseFont).GetNativeFont();
HFONT font = Combobox::GetFont().GetNativeFont();
SendMessage(native_view(), WM_SETFONT, reinterpret_cast<WPARAM>(font), FALSE);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment