summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorsaintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-06 03:12:40 +0000
committersaintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-06 03:12:40 +0000
commit5c53b095d2e8d1add4c24ac1b9949f28dad0adc1 (patch)
tree69439c544b4b69ce1f31aef9e201983e2942c2a9 /ui
parent1ad2e581bdc02ae097353f913069e10fb74580ff (diff)
downloadchromium_src-5c53b095d2e8d1add4c24ac1b9949f28dad0adc1.zip
chromium_src-5c53b095d2e8d1add4c24ac1b9949f28dad0adc1.tar.gz
chromium_src-5c53b095d2e8d1add4c24ac1b9949f28dad0adc1.tar.bz2
Use the correct disclosure arrow for views::ComboBox and correct positioning formulas.
(note that the asset was checked in earlier today to allow for successful trybots run with this CL). This is getting us one step closer to the polished look, but is not finished. I still need to rework the menu positioning which I will do as a separate CL. BUG=100663 TEST=none Review URL: http://codereview.chromium.org/9110021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116636 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/resources/ui_resources.grd1
-rw-r--r--ui/views/controls/combobox/native_combobox_views.cc86
-rw-r--r--ui/views/controls/combobox/native_combobox_views.h9
3 files changed, 31 insertions, 65 deletions
diff --git a/ui/resources/ui_resources.grd b/ui/resources/ui_resources.grd
index 37612c86..d64052c 100644
--- a/ui/resources/ui_resources.grd
+++ b/ui/resources/ui_resources.grd
@@ -127,6 +127,7 @@
<include name="IDR_CLOSE_SA" file="close_sa.png" type="BINDATA" />
<include name="IDR_CLOSE_SA_H" file="close_sa_h.png" type="BINDATA" />
<include name="IDR_CLOSE_SA_P" file="close_sa_p.png" type="BINDATA" />
+ <include name="IDR_DISCLOSURE_ARROW" file="discloure_arrow.png" type="BINDATA" />
<include name="IDR_MENU_ARROW" file="menu_arrow.png" type="BINDATA" />
<include name="IDR_MENU_CHECK" file="menu_check.png" type="BINDATA" />
</if>
diff --git a/ui/views/controls/combobox/native_combobox_views.cc b/ui/views/controls/combobox/native_combobox_views.cc
index 032be73..008cc29 100644
--- a/ui/views/controls/combobox/native_combobox_views.cc
+++ b/ui/views/controls/combobox/native_combobox_views.cc
@@ -1,4 +1,4 @@
-// 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.
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/utf_string_conversions.h"
+#include "grit/ui_resources.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/models/combobox_model.h"
#include "ui/base/resource/resource_bundle.h"
@@ -24,10 +25,6 @@
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h"
-#if defined(OS_LINUX)
-#include "ui/gfx/gtk_util.h"
-#endif
-
namespace {
// Define the size of the insets.
@@ -39,15 +36,13 @@ const int kRightInsetSize = 4;
// Limit how small a combobox can be.
const int kMinComboboxWidth = 148;
-// Size of the combobox arrow.
-const int kComboboxArrowSize = 9;
-const int kComboboxArrowOffset = 7;
-const int kComboboxArrowMargin = 12;
+// Size of the combobox arrow margins
+const int kDisclosureArrowLeftPadding = 7;
+const int kDisclosureArrowRightPadding = 7;
// Color settings for text and border.
// These are tentative, and should be derived from theme, system
// settings and current settings.
-const SkColor kDefaultBorderColor = SK_ColorGRAY;
const SkColor kTextColor = SK_ColorBLACK;
// Define the id of the first item in the menu (since it needs to be > 0)
@@ -63,6 +58,8 @@ const char NativeComboboxViews::kViewClassName[] =
NativeComboboxViews::NativeComboboxViews(Combobox* parent)
: combobox_(parent),
text_border_(new FocusableBorder()),
+ disclosure_arrow_(ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ IDR_DISCLOSURE_ARROW)),
dropdown_open_(false),
selected_item_(-1),
content_width_(0),
@@ -205,12 +202,14 @@ gfx::Size NativeComboboxViews::GetPreferredSize() {
if (content_width_ == 0)
UpdateFromModel();
- // TODO(saintlou) the preferred size will drive the local bounds
- // which in turn is used to set the minimum width for the dropdown
+ // The preferred size will drive the local bounds which in turn is used to set
+ // the minimum width for the dropdown list.
gfx::Insets insets = GetInsets();
- return gfx::Size(std::min(kMinComboboxWidth,
- content_width_ + 2 * (insets.width())),
- content_height_ + 2 * (insets.height()));
+ int total_width = content_width_ + (2 * insets.width())
+ + kDisclosureArrowLeftPadding + disclosure_arrow_->width()
+ + kDisclosureArrowRightPadding;
+ return gfx::Size(std::min(kMinComboboxWidth, total_width),
+ content_height_ + (2 * insets.height()));
}
View* NativeComboboxViews::GetView() {
@@ -274,30 +273,6 @@ const gfx::Font& NativeComboboxViews::GetFont() const {
return rb.GetFont(ResourceBundle::BaseFont);
}
-// tip_x and tip_y are the coordinates of the tip of an arrow head which is
-// drawn as an isoscele triangle
-// shift_x and shift_y are offset from tip_x and tip_y to specify the relative
-// positions of the 2 equal angles (ie not the angle at the tip of the arrow)
-// Note: the width of the base (the side opposite the tip) is 2 * shift_x
-void NativeComboboxViews::DrawArrow(gfx::Canvas* canvas,
- int tip_x,
- int tip_y,
- int shift_x,
- int shift_y) const {
- SkPaint paint;
- paint.setStyle(SkPaint::kStrokeAndFill_Style);
- paint.setColor(kTextColor);
- paint.setAntiAlias(true);
- gfx::Path path;
- path.incReserve(4);
- path.moveTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y));
- path.lineTo(SkIntToScalar(tip_x + shift_x), SkIntToScalar(tip_y + shift_y));
- path.lineTo(SkIntToScalar(tip_x - shift_x), SkIntToScalar(tip_y + shift_y));
- path.close();
- canvas->GetSkCanvas()->drawPath(path, paint);
-}
-
-
void NativeComboboxViews::PaintText(gfx::Canvas* canvas) {
gfx::Insets insets = GetInsets();
@@ -314,30 +289,21 @@ void NativeComboboxViews::PaintText(gfx::Canvas* canvas) {
index = 0;
string16 text = combobox_->model()->GetItemAt(index);
+ int disclosure_arrow_offset = width() - disclosure_arrow_->width()
+ - kDisclosureArrowLeftPadding - kDisclosureArrowRightPadding;
+
const gfx::Font& font = GetFont();
- int width = font.GetStringWidth(text);
+ int text_width = font.GetStringWidth(text);
+ if ((text_width + insets.width()) > disclosure_arrow_offset)
+ text_width = disclosure_arrow_offset - insets.width();
- canvas->DrawStringInt(text, font, text_color, x, y, width, text_height);
+ canvas->DrawStringInt(text, font, text_color, x, y, text_width, text_height);
- // draw the double arrow
- gfx::Rect lb = GetLocalBounds();
- DrawArrow(canvas,
- lb.width() - (kComboboxArrowSize / 2) - kComboboxArrowOffset,
- lb.height() / 2 - kComboboxArrowSize,
- kComboboxArrowSize / 2,
- kComboboxArrowSize - 2);
- DrawArrow(canvas,
- lb.width() - (kComboboxArrowSize / 2) - kComboboxArrowOffset,
- lb.height() / 2 + kComboboxArrowSize,
- -kComboboxArrowSize / 2,
- -(kComboboxArrowSize - 2));
-
- // draw the margin
- canvas->DrawLineInt(kDefaultBorderColor,
- lb.width() - kComboboxArrowSize - kComboboxArrowMargin,
- kTopInsetSize,
- lb.width() - kComboboxArrowSize - kComboboxArrowMargin,
- lb.height() - kBottomInsetSize);
+ gfx::Rect arrow_bounds(disclosure_arrow_offset + kDisclosureArrowLeftPadding,
+ height() / 2 - disclosure_arrow_->height() / 2,
+ disclosure_arrow_->width(),
+ disclosure_arrow_->height());
+ canvas->DrawBitmapInt(*disclosure_arrow_, arrow_bounds.x(), arrow_bounds.y());
canvas->Restore();
}
diff --git a/ui/views/controls/combobox/native_combobox_views.h b/ui/views/controls/combobox/native_combobox_views.h
index 61c70a3..8b5687c 100644
--- a/ui/views/controls/combobox/native_combobox_views.h
+++ b/ui/views/controls/combobox/native_combobox_views.h
@@ -1,4 +1,4 @@
-// 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.
@@ -67,10 +67,6 @@ class NativeComboboxViews : public views::View,
// Returns the Combobox's font.
const gfx::Font& GetFont() const;
- // Draw an arrow
- void DrawArrow(gfx::Canvas* canvas,
- int tip_x, int tip_y, int shift_x, int shift_y) const;
-
// Draw the selected value of the drop down list
void PaintText(gfx::Canvas* canvas);
@@ -83,6 +79,9 @@ class NativeComboboxViews : public views::View,
// The reference to the border class. The object is owned by View::border_.
FocusableBorder* text_border_;
+ // The disclosure arrow next to the currently selected item from the list.
+ const SkBitmap* disclosure_arrow_;
+
// Responsible for showing the context menu.
scoped_ptr<MenuRunner> dropdown_list_menu_runner_;