summaryrefslogtreecommitdiffstats
path: root/views/controls/button
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-28 01:32:00 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-28 01:32:00 +0000
commit48977d584e9516d70222e5c9b62c01e3516b5283 (patch)
tree92751c3d38a0db9ca1eb1b5eecf20ff7ab773a97 /views/controls/button
parent5b14c320879a30f95c2ba55b32b5ab55f56c43c4 (diff)
downloadchromium_src-48977d584e9516d70222e5c9b62c01e3516b5283.zip
chromium_src-48977d584e9516d70222e5c9b62c01e3516b5283.tar.gz
chromium_src-48977d584e9516d70222e5c9b62c01e3516b5283.tar.bz2
views: Move button directory to ui/views/controls/.
BUG=104039 R=maruel@chromium.org TBR=ben@chromium.org Review URL: http://codereview.chromium.org/8716001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111669 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/button')
-rw-r--r--views/controls/button/button.cc68
-rw-r--r--views/controls/button/button.h79
-rw-r--r--views/controls/button/button_dropdown.cc194
-rw-r--r--views/controls/button/button_dropdown.h73
-rw-r--r--views/controls/button/checkbox.cc112
-rw-r--r--views/controls/button/checkbox.h60
-rw-r--r--views/controls/button/custom_button.cc295
-rw-r--r--views/controls/button/custom_button.h149
-rw-r--r--views/controls/button/image_button.cc174
-rw-r--r--views/controls/button/image_button.h123
-rw-r--r--views/controls/button/menu_button.cc263
-rw-r--r--views/controls/button/menu_button.h105
-rw-r--r--views/controls/button/radio_button.cc104
-rw-r--r--views/controls/button/radio_button.h46
-rw-r--r--views/controls/button/text_button.cc860
-rw-r--r--views/controls/button/text_button.h431
16 files changed, 0 insertions, 3136 deletions
diff --git a/views/controls/button/button.cc b/views/controls/button/button.cc
deleted file mode 100644
index c43439c..0000000
--- a/views/controls/button/button.cc
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "views/controls/button/button.h"
-
-#include "base/utf_string_conversions.h"
-#include "ui/base/accessibility/accessible_view_state.h"
-
-namespace views {
-
-////////////////////////////////////////////////////////////////////////////////
-// Button, public:
-
-Button::~Button() {
-}
-
-void Button::SetTooltipText(const string16& tooltip_text) {
- tooltip_text_ = tooltip_text;
- TooltipTextChanged();
-}
-
-void Button::SetAccessibleName(const string16& name) {
- accessible_name_ = name;
-}
-
-void Button::SetAccessibleKeyboardShortcut(const string16& shortcut) {
- accessible_shortcut_ = shortcut;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// Button, View overrides:
-
-bool Button::GetTooltipText(const gfx::Point& p, string16* tooltip) const {
- if (tooltip_text_.empty())
- return false;
-
- *tooltip = tooltip_text_;
- return true;
-}
-
-void Button::GetAccessibleState(ui::AccessibleViewState* state) {
- state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
- state->name = accessible_name_;
- state->keyboard_shortcut = accessible_shortcut_;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// Button, protected:
-
-Button::Button(ButtonListener* listener)
- : listener_(listener),
- tag_(-1),
- mouse_event_flags_(0) {
- set_accessibility_focusable(true);
-}
-
-void Button::NotifyClick(const views::Event& event) {
- mouse_event_flags_ = event.IsMouseEvent() ? event.flags() : 0;
- // We can be called when there is no listener, in cases like double clicks on
- // menu buttons etc.
- if (listener_)
- listener_->ButtonPressed(this, event);
- // NOTE: don't attempt to reset mouse_event_flags_ as the listener may have
- // deleted us.
-}
-
-} // namespace views
diff --git a/views/controls/button/button.h b/views/controls/button/button.h
deleted file mode 100644
index 0884ea1..0000000
--- a/views/controls/button/button.h
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef VIEWS_CONTROLS_BUTTON_BUTTON_H_
-#define VIEWS_CONTROLS_BUTTON_BUTTON_H_
-#pragma once
-
-#include "views/view.h"
-
-namespace views {
-
-class Button;
-class Event;
-
-// An interface implemented by an object to let it know that a button was
-// pressed.
-class VIEWS_EXPORT ButtonListener {
- public:
- virtual void ButtonPressed(Button* sender, const views::Event& event) = 0;
-
- protected:
- virtual ~ButtonListener() {}
-};
-
-// A View representing a button. Depending on the specific type, the button
-// could be implemented by a native control or custom rendered.
-class VIEWS_EXPORT Button : public View {
- public:
- virtual ~Button();
-
- void SetTooltipText(const string16& tooltip_text);
-
- int tag() const { return tag_; }
- void set_tag(int tag) { tag_ = tag; }
-
- int mouse_event_flags() const { return mouse_event_flags_; }
-
- void SetAccessibleName(const string16& name);
- void SetAccessibleKeyboardShortcut(const string16& shortcut);
-
- // Overridden from View:
- virtual bool GetTooltipText(const gfx::Point& p,
- string16* tooltip) const OVERRIDE;
- virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
-
- protected:
- // Construct the Button with a Listener. The listener can be NULL. This can be
- // true of buttons that don't have a listener - e.g. menubuttons where there's
- // no default action and checkboxes.
- explicit Button(ButtonListener* listener);
-
- // Cause the button to notify the listener that a click occurred.
- virtual void NotifyClick(const views::Event& event);
-
- // The button's listener. Notified when clicked.
- ButtonListener* listener_;
-
- private:
- // The text shown in a tooltip.
- string16 tooltip_text_;
-
- // Accessibility data.
- string16 accessible_name_;
- string16 accessible_shortcut_;
-
- // The id tag associated with this button. Used to disambiguate buttons in
- // the ButtonListener implementation.
- int tag_;
-
- // Event flags present when the button was clicked.
- int mouse_event_flags_;
-
- DISALLOW_COPY_AND_ASSIGN(Button);
-};
-
-} // namespace views
-
-#endif // VIEWS_CONTROLS_BUTTON_BUTTON_H_
diff --git a/views/controls/button/button_dropdown.cc b/views/controls/button/button_dropdown.cc
deleted file mode 100644
index 7df2164..0000000
--- a/views/controls/button/button_dropdown.cc
+++ /dev/null
@@ -1,194 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "views/controls/button/button_dropdown.h"
-
-#include "base/bind.h"
-#include "base/compiler_specific.h"
-#include "base/message_loop.h"
-#include "base/utf_string_conversions.h"
-#include "grit/ui_strings.h"
-#include "ui/base/accessibility/accessible_view_state.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/models/menu_model.h"
-#include "ui/views/widget/widget.h"
-#include "views/controls/menu/menu_item_view.h"
-#include "views/controls/menu/menu_model_adapter.h"
-#include "views/controls/menu/menu_runner.h"
-
-namespace views {
-
-// static
-const char ButtonDropDown::kViewClassName[] =
- "views/controls/button/ButtonDropDown";
-
-// How long to wait before showing the menu.
-const int kMenuTimerDelay = 500;
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// ButtonDropDown - constructors, destructors, initialization, cleanup
-//
-////////////////////////////////////////////////////////////////////////////////
-
-ButtonDropDown::ButtonDropDown(ButtonListener* listener, ui::MenuModel* model)
- : ImageButton(listener),
- model_(model),
- y_position_on_lbuttondown_(0),
- ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_factory_(this)) {
-}
-
-ButtonDropDown::~ButtonDropDown() {
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// ButtonDropDown - Events
-//
-////////////////////////////////////////////////////////////////////////////////
-
-bool ButtonDropDown::OnMousePressed(const MouseEvent& event) {
- if (IsEnabled() && IsTriggerableEvent(event) && HitTest(event.location())) {
- // Store the y pos of the mouse coordinates so we can use them later to
- // determine if the user dragged the mouse down (which should pop up the
- // drag down menu immediately, instead of waiting for the timer)
- y_position_on_lbuttondown_ = event.y();
-
- // Schedule a task that will show the menu.
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&ButtonDropDown::ShowDropDownMenu,
- show_menu_factory_.GetWeakPtr(),
- GetWidget()->GetNativeView()),
- kMenuTimerDelay);
- }
- return ImageButton::OnMousePressed(event);
-}
-
-bool ButtonDropDown::OnMouseDragged(const MouseEvent& event) {
- bool result = ImageButton::OnMouseDragged(event);
-
- if (show_menu_factory_.HasWeakPtrs()) {
- // If the mouse is dragged to a y position lower than where it was when
- // clicked then we should not wait for the menu to appear but show
- // it immediately.
- if (event.y() > y_position_on_lbuttondown_ + GetHorizontalDragThreshold()) {
- show_menu_factory_.InvalidateWeakPtrs();
- ShowDropDownMenu(GetWidget()->GetNativeView());
- }
- }
-
- return result;
-}
-
-void ButtonDropDown::OnMouseReleased(const MouseEvent& event) {
- if (IsTriggerableEvent(event) ||
- (event.IsRightMouseButton() && !HitTest(event.location()))) {
- ImageButton::OnMouseReleased(event);
- }
-
- if (IsTriggerableEvent(event))
- show_menu_factory_.InvalidateWeakPtrs();
-
- if (IsEnabled() && event.IsRightMouseButton() && HitTest(event.location())) {
- show_menu_factory_.InvalidateWeakPtrs();
- ShowDropDownMenu(GetWidget()->GetNativeView());
- }
-}
-
-std::string ButtonDropDown::GetClassName() const {
- return kViewClassName;
-}
-
-void ButtonDropDown::OnMouseExited(const MouseEvent& event) {
- // Starting a drag results in a MouseExited, we need to ignore it.
- // A right click release triggers an exit event. We want to
- // remain in a PUSHED state until the drop down menu closes.
- if (state_ != BS_DISABLED && !InDrag() && state_ != BS_PUSHED)
- SetState(BS_NORMAL);
-}
-
-void ButtonDropDown::ShowContextMenu(const gfx::Point& p,
- bool is_mouse_gesture) {
- show_menu_factory_.InvalidateWeakPtrs();
- ShowDropDownMenu(GetWidget()->GetNativeView());
- SetState(BS_HOT);
-}
-
-void ButtonDropDown::GetAccessibleState(ui::AccessibleViewState* state) {
- CustomButton::GetAccessibleState(state);
- state->role = ui::AccessibilityTypes::ROLE_BUTTONDROPDOWN;
- state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS);
- state->state = ui::AccessibilityTypes::STATE_HASPOPUP;
-}
-
-bool ButtonDropDown::ShouldEnterPushedState(const MouseEvent& event) {
- // Enter PUSHED state on press with Left or Right mouse button. Remain
- // in this state while the context menu is open.
- return ((ui::EF_LEFT_BUTTON_DOWN |
- ui::EF_RIGHT_BUTTON_DOWN) & event.flags()) != 0;
-}
-
-void ButtonDropDown::ShowDropDownMenu(gfx::NativeView window) {
- gfx::Rect lb = GetLocalBounds();
-
- // Both the menu position and the menu anchor type change if the UI layout
- // is right-to-left.
- gfx::Point menu_position(lb.origin());
- menu_position.Offset(0, lb.height() - 1);
- if (base::i18n::IsRTL())
- menu_position.Offset(lb.width() - 1, 0);
-
- View::ConvertPointToScreen(this, &menu_position);
-
-#if defined(OS_WIN)
- int left_bound = GetSystemMetrics(SM_XVIRTUALSCREEN);
-#else
- int left_bound = 0;
- NOTIMPLEMENTED();
-#endif
- if (menu_position.x() < left_bound)
- menu_position.set_x(left_bound);
-
- // Make the button look depressed while the menu is open.
- SetState(BS_PUSHED);
-
- // Create and run menu. Display an empty menu if model is NULL.
- if (model_) {
- MenuModelAdapter menu_delegate(model_);
- menu_delegate.set_triggerable_event_flags(triggerable_event_flags());
- MenuRunner runner(menu_delegate.CreateMenu());
- if (runner.RunMenuAt(GetWidget(), NULL,
- gfx::Rect(menu_position, gfx::Size(0, 0)),
- MenuItemView::TOPLEFT,
- MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED)
- return;
- } else {
- MenuDelegate menu_delegate;
- MenuItemView* menu = new MenuItemView(&menu_delegate);
- MenuRunner runner(menu);
- if (runner.RunMenuAt(GetWidget(), NULL,
- gfx::Rect(menu_position, gfx::Size(0, 0)),
- views::MenuItemView::TOPLEFT,
- MenuRunner::HAS_MNEMONICS) == MenuRunner::MENU_DELETED)
- return;
- }
-
- // Need to explicitly clear mouse handler so that events get sent
- // properly after the menu finishes running. If we don't do this, then
- // the first click to other parts of the UI is eaten.
- SetMouseHandler(NULL);
-
- // Set the state back to normal after the drop down menu is closed.
- if (state_ != BS_DISABLED)
- SetState(BS_NORMAL);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// ButtonDropDown - Accessibility
-//
-////////////////////////////////////////////////////////////////////////////////
-
-} // namespace views
diff --git a/views/controls/button/button_dropdown.h b/views/controls/button/button_dropdown.h
deleted file mode 100644
index 65d62ed..0000000
--- a/views/controls/button/button_dropdown.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_
-#define VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_
-#pragma once
-
-#include "base/memory/weak_ptr.h"
-#include "views/controls/button/image_button.h"
-
-namespace ui {
-class MenuModel;
-}
-
-namespace views {
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// ButtonDropDown
-//
-// A button class that when pressed (and held) or pressed (and drag down) will
-// display a menu
-//
-////////////////////////////////////////////////////////////////////////////////
-class VIEWS_EXPORT ButtonDropDown : public ImageButton {
- public:
- // The button's class name.
- static const char kViewClassName[];
-
- ButtonDropDown(ButtonListener* listener, ui::MenuModel* model);
- virtual ~ButtonDropDown();
-
- // Overridden from views::View
- virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
- virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE;
- virtual std::string GetClassName() const OVERRIDE;
- // Showing the drop down results in a MouseCaptureLost, we need to ignore it.
- virtual void OnMouseCaptureLost() OVERRIDE {}
- virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
- // Display the right-click menu, as triggered by the keyboard, for instance.
- // Using the member function ShowDropDownMenu for the actual display.
- virtual void ShowContextMenu(const gfx::Point& p,
- bool is_mouse_gesture) OVERRIDE;
- virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
-
- protected:
- // Overridden from CustomButton. Returns true if the button should become
- // pressed when a user holds the mouse down over the button. For this
- // implementation, both left and right mouse buttons can trigger a change
- // to the PUSHED state.
- virtual bool ShouldEnterPushedState(const MouseEvent& event) OVERRIDE;
-
- private:
- // Internal function to show the dropdown menu
- void ShowDropDownMenu(gfx::NativeView window);
-
- // The model that populates the attached menu.
- ui::MenuModel* model_;
-
- // Y position of mouse when left mouse button is pressed
- int y_position_on_lbuttondown_;
-
- // A factory for tasks that show the dropdown context menu for the button.
- base::WeakPtrFactory<ButtonDropDown> show_menu_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(ButtonDropDown);
-};
-
-} // namespace views
-
-#endif // VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_
diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc
deleted file mode 100644
index da2b04c..0000000
--- a/views/controls/button/checkbox.cc
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "views/controls/button/checkbox.h"
-
-#include "base/logging.h"
-#include "ui/base/accessibility/accessible_view_state.h"
-#include "ui/gfx/canvas.h"
-#include "views/controls/label.h"
-
-namespace views {
-
-const int kCheckboxLabelSpacing = 4;
-
-// static
-const char Checkbox::kViewClassName[] = "views/Checkbox";
-
-////////////////////////////////////////////////////////////////////////////////
-// Checkbox, public:
-
-Checkbox::Checkbox(const string16& label)
- : TextButtonBase(NULL, label),
- checked_(false) {
- set_border(new TextButtonNativeThemeBorder(this));
- set_focusable(true);
-}
-
-Checkbox::~Checkbox() {
-}
-
-void Checkbox::SetChecked(bool checked) {
- checked_ = checked;
- SchedulePaint();
-}
-
-gfx::Size Checkbox::GetPreferredSize() {
- gfx::Size prefsize(TextButtonBase::GetPreferredSize());
- gfx::NativeTheme::ExtraParams extra;
- gfx::NativeTheme::State state = GetThemeState(&extra);
- gfx::Size size = gfx::NativeTheme::instance()->GetPartSize(GetThemePart(),
- state,
- extra);
- prefsize.Enlarge(size.width(), 0);
- prefsize.set_height(std::max(prefsize.height(), size.height()));
-
- if (max_width_ > 0)
- prefsize.set_width(std::min(max_width_, prefsize.width()));
-
- return prefsize;
-}
-
-std::string Checkbox::GetClassName() const {
- return kViewClassName;
-}
-
-void Checkbox::GetAccessibleState(ui::AccessibleViewState* state) {
- TextButtonBase::GetAccessibleState(state);
- state->role = ui::AccessibilityTypes::ROLE_CHECKBUTTON;
- state->state = checked() ? ui::AccessibilityTypes::STATE_CHECKED : 0;
-}
-
-void Checkbox::OnPaintFocusBorder(gfx::Canvas* canvas) {
- if (HasFocus() && (IsFocusable() || IsAccessibilityFocusableInRootView())) {
- gfx::Rect bounds(GetTextBounds());
- // Increate the bounding box by one on each side so that that focus border
- // does not draw on top of the letters.
- bounds.Inset(-1, -1, -1, -1);
- canvas->DrawFocusRect(bounds);
- }
-}
-
-void Checkbox::NotifyClick(const views::Event& event) {
- SetChecked(!checked());
- RequestFocus();
- TextButtonBase::NotifyClick(event);
-}
-
-gfx::NativeTheme::Part Checkbox::GetThemePart() const {
- return gfx::NativeTheme::kCheckbox;
-}
-
-gfx::Rect Checkbox::GetThemePaintRect() const {
- gfx::NativeTheme::ExtraParams extra;
- gfx::NativeTheme::State state = GetThemeState(&extra);
- gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(),
- state,
- extra));
- gfx::Insets insets = GetInsets();
- int y_offset = (height() - size.height()) / 2;
- gfx::Rect rect(insets.left(), y_offset, size.width(), size.height());
- rect.set_x(GetMirroredXForRect(rect));
- return rect;
-}
-
-void Checkbox::GetExtraParams(gfx::NativeTheme::ExtraParams* params) const {
- TextButtonBase::GetExtraParams(params);
- params->button.checked = checked_;
-}
-
-gfx::Rect Checkbox::GetTextBounds() const {
- gfx::Rect bounds(TextButtonBase::GetTextBounds());
- gfx::NativeTheme::ExtraParams extra;
- gfx::NativeTheme::State state = GetThemeState(&extra);
- gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(),
- state,
- extra));
- bounds.Offset(size.width() + kCheckboxLabelSpacing, 0);
- return bounds;
-}
-
-} // namespace views
diff --git a/views/controls/button/checkbox.h b/views/controls/button/checkbox.h
deleted file mode 100644
index 723f1ea..0000000
--- a/views/controls/button/checkbox.h
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef VIEWS_CONTROLS_BUTTON_CHECKBOX_H_
-#define VIEWS_CONTROLS_BUTTON_CHECKBOX_H_
-#pragma once
-
-#include <string>
-
-#include "base/compiler_specific.h"
-#include "base/string16.h"
-#include "views/controls/button/text_button.h"
-
-namespace views {
-
-// A native themed class representing a checkbox. This class does not use
-// platform specific objects to replicate the native platforms looks and feel.
-class VIEWS_EXPORT Checkbox : public TextButtonBase {
- public:
- static const char kViewClassName[];
-
- explicit Checkbox(const string16& label);
- virtual ~Checkbox();
-
- // Sets a listener for this checkbox. Checkboxes aren't required to have them
- // since their state can be read independently of them being toggled.
- void set_listener(ButtonListener* listener) { listener_ = listener; }
-
- // Sets/Gets whether or not the checkbox is checked.
- virtual void SetChecked(bool checked);
- bool checked() const { return checked_; }
-
- protected:
- // Overridden from View:
- virtual gfx::Size GetPreferredSize() OVERRIDE;
- virtual std::string GetClassName() const OVERRIDE;
- virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
- virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
-
- private:
- // Overridden from Button:
- virtual void NotifyClick(const views::Event& event) OVERRIDE;
-
- // Overridden from TextButtonBase:
- virtual gfx::NativeTheme::Part GetThemePart() const OVERRIDE;
- virtual gfx::Rect GetThemePaintRect() const OVERRIDE;
- virtual void GetExtraParams(
- gfx::NativeTheme::ExtraParams* params) const OVERRIDE;
- virtual gfx::Rect GetTextBounds() const OVERRIDE;
-
- // True if the checkbox is checked.
- bool checked_;
-
- DISALLOW_COPY_AND_ASSIGN(Checkbox);
-};
-
-} // namespace views
-
-#endif // VIEWS_CONTROLS_BUTTON_CHECKBOX_H_
diff --git a/views/controls/button/custom_button.cc b/views/controls/button/custom_button.cc
deleted file mode 100644
index a4233b9..0000000
--- a/views/controls/button/custom_button.cc
+++ /dev/null
@@ -1,295 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "views/controls/button/custom_button.h"
-
-#include "ui/base/accessibility/accessible_view_state.h"
-#include "ui/base/animation/throb_animation.h"
-#include "ui/base/keycodes/keyboard_codes.h"
-#include "ui/gfx/screen.h"
-#include "ui/views/widget/widget.h"
-
-namespace views {
-
-// How long the hover animation takes if uninterrupted.
-static const int kHoverFadeDurationMs = 150;
-
-// static
-const char CustomButton::kViewClassName[] = "views/CustomButton";
-
-////////////////////////////////////////////////////////////////////////////////
-// CustomButton, public:
-
-CustomButton::~CustomButton() {
-}
-
-void CustomButton::SetState(ButtonState state) {
- if (state == state_)
- return;
-
- if (animate_on_state_change_ &&
- (!is_throbbing_ || !hover_animation_->is_animating())) {
- is_throbbing_ = false;
- if (state_ == BS_NORMAL && state == BS_HOT) {
- // Button is hovered from a normal state, start hover animation.
- hover_animation_->Show();
- } else if ((state_ == BS_HOT || state_ == BS_PUSHED)
- && state == BS_NORMAL) {
- // Button is returning to a normal state from hover, start hover
- // fade animation.
- hover_animation_->Hide();
- } else {
- hover_animation_->Stop();
- }
- }
-
- state_ = state;
- StateChanged();
- SchedulePaint();
-}
-
-void CustomButton::StartThrobbing(int cycles_til_stop) {
- is_throbbing_ = true;
- hover_animation_->StartThrobbing(cycles_til_stop);
-}
-
-void CustomButton::StopThrobbing() {
- if (hover_animation_->is_animating()) {
- hover_animation_->Stop();
- SchedulePaint();
- }
-}
-
-void CustomButton::SetAnimationDuration(int duration) {
- hover_animation_->SetSlideDuration(duration);
-}
-
-bool CustomButton::IsMouseHovered() const {
- // If we haven't yet been placed in an onscreen view hierarchy, we can't be
- // hovered.
- if (!GetWidget())
- return false;
-
- gfx::Point cursor_pos(gfx::Screen::GetCursorScreenPoint());
- ConvertPointToView(NULL, this, &cursor_pos);
- return HitTest(cursor_pos);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// CustomButton, View overrides:
-
-void CustomButton::SetHotTracked(bool flag) {
- if (state_ != BS_DISABLED)
- SetState(flag ? BS_HOT : BS_NORMAL);
-
- if (flag && GetWidget()) {
- GetWidget()->NotifyAccessibilityEvent(
- this, ui::AccessibilityTypes::EVENT_FOCUS, true);
- }
-}
-
-bool CustomButton::IsHotTracked() const {
- return state_ == BS_HOT;
-}
-
-void CustomButton::OnEnabledChanged() {
- if (View::IsEnabled() ? (state_ != BS_DISABLED) : (state_ == BS_DISABLED))
- return;
-
- if (View::IsEnabled())
- SetState(IsMouseHovered() ? BS_HOT : BS_NORMAL);
- else
- SetState(BS_DISABLED);
-}
-
-bool CustomButton::IsEnabled() const {
- return state_ != BS_DISABLED;
-}
-
-std::string CustomButton::GetClassName() const {
- return kViewClassName;
-}
-
-bool CustomButton::OnMousePressed(const MouseEvent& event) {
- if (state_ != BS_DISABLED) {
- if (ShouldEnterPushedState(event) && HitTest(event.location()))
- SetState(BS_PUSHED);
- if (request_focus_on_press_)
- RequestFocus();
- }
- return true;
-}
-
-bool CustomButton::OnMouseDragged(const MouseEvent& event) {
- if (state_ != BS_DISABLED) {
- if (HitTest(event.location()))
- SetState(ShouldEnterPushedState(event) ? BS_PUSHED : BS_HOT);
- else
- SetState(BS_NORMAL);
- }
- return true;
-}
-
-void CustomButton::OnMouseReleased(const MouseEvent& event) {
- if (state_ == BS_DISABLED)
- return;
-
- if (!HitTest(event.location())) {
- SetState(BS_NORMAL);
- return;
- }
-
- SetState(BS_HOT);
- if (IsTriggerableEvent(event)) {
- NotifyClick(event);
- // NOTE: We may be deleted at this point (by the listener's notification
- // handler).
- }
-}
-
-void CustomButton::OnMouseCaptureLost() {
- // Starting a drag results in a MouseCaptureLost, we need to ignore it.
- if (state_ != BS_DISABLED && !InDrag())
- SetState(BS_NORMAL);
-}
-
-void CustomButton::OnMouseEntered(const MouseEvent& event) {
- if (state_ != BS_DISABLED)
- SetState(BS_HOT);
-}
-
-void CustomButton::OnMouseExited(const MouseEvent& event) {
- // Starting a drag results in a MouseExited, we need to ignore it.
- if (state_ != BS_DISABLED && !InDrag())
- SetState(BS_NORMAL);
-}
-
-void CustomButton::OnMouseMoved(const MouseEvent& event) {
- if (state_ != BS_DISABLED)
- SetState(HitTest(event.location()) ? BS_HOT : BS_NORMAL);
-}
-
-bool CustomButton::OnKeyPressed(const KeyEvent& event) {
- if (state_ == BS_DISABLED)
- return false;
-
- // Space sets button state to pushed. Enter clicks the button. This matches
- // the Windows native behavior of buttons, where Space clicks the button on
- // KeyRelease and Enter clicks the button on KeyPressed.
- if (event.key_code() == ui::VKEY_SPACE) {
- SetState(BS_PUSHED);
- } else if (event.key_code() == ui::VKEY_RETURN) {
- SetState(BS_NORMAL);
- NotifyClick(event);
- } else {
- return false;
- }
- return true;
-}
-
-bool CustomButton::OnKeyReleased(const KeyEvent& event) {
- if ((state_ == BS_DISABLED) || (event.key_code() != ui::VKEY_SPACE))
- return false;
-
- SetState(BS_NORMAL);
- NotifyClick(event);
- return true;
-}
-
-bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) {
- if (!View::IsEnabled())
- return false;
-
- SetState(BS_NORMAL);
- KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.key_code(),
- accelerator.modifiers());
- NotifyClick(key_event);
- return true;
-}
-
-void CustomButton::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) {
- if (!context_menu_controller())
- return;
-
- // We're about to show the context menu. Showing the context menu likely means
- // we won't get a mouse exited and reset state. Reset it now to be sure.
- if (state_ != BS_DISABLED)
- SetState(BS_NORMAL);
- View::ShowContextMenu(p, is_mouse_gesture);
-}
-
-void CustomButton::OnDragDone() {
- SetState(BS_NORMAL);
-}
-
-void CustomButton::GetAccessibleState(ui::AccessibleViewState* state) {
- Button::GetAccessibleState(state);
- switch (state_) {
- case BS_HOT:
- state->state = ui::AccessibilityTypes::STATE_HOTTRACKED;
- break;
- case BS_PUSHED:
- state->state = ui::AccessibilityTypes::STATE_PRESSED;
- break;
- case BS_DISABLED:
- state->state = ui::AccessibilityTypes::STATE_UNAVAILABLE;
- break;
- case BS_NORMAL:
- case BS_COUNT:
- // No additional accessibility state set for this button state.
- break;
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// CustomButton, ui::AnimationDelegate implementation:
-
-void CustomButton::AnimationProgressed(const ui::Animation* animation) {
- SchedulePaint();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// CustomButton, protected:
-
-CustomButton::CustomButton(ButtonListener* listener)
- : Button(listener),
- state_(BS_NORMAL),
- animate_on_state_change_(true),
- is_throbbing_(false),
- triggerable_event_flags_(ui::EF_LEFT_BUTTON_DOWN),
- request_focus_on_press_(true) {
- hover_animation_.reset(new ui::ThrobAnimation(this));
- hover_animation_->SetSlideDuration(kHoverFadeDurationMs);
-}
-
-void CustomButton::StateChanged() {
-}
-
-bool CustomButton::IsTriggerableEvent(const MouseEvent& event) {
- return (triggerable_event_flags_ & event.flags()) != 0;
-}
-
-bool CustomButton::ShouldEnterPushedState(const MouseEvent& event) {
- return IsTriggerableEvent(event);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// CustomButton, View overrides (protected):
-
-void CustomButton::ViewHierarchyChanged(bool is_add, View *parent,
- View *child) {
- if (!is_add && state_ != BS_DISABLED)
- SetState(BS_NORMAL);
-}
-
-bool CustomButton::IsFocusable() const {
- return (state_ != BS_DISABLED) && View::IsFocusable();
-}
-
-void CustomButton::OnBlur() {
- if (IsHotTracked())
- SetState(BS_NORMAL);
-}
-
-} // namespace views
diff --git a/views/controls/button/custom_button.h b/views/controls/button/custom_button.h
deleted file mode 100644
index ae6a8bf..0000000
--- a/views/controls/button/custom_button.h
+++ /dev/null
@@ -1,149 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_
-#define VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_
-#pragma once
-
-#include "ui/base/animation/animation_delegate.h"
-#include "views/controls/button/button.h"
-
-namespace ui {
-class ThrobAnimation;
-}
-
-namespace views {
-
-// A button with custom rendering. The common base class of ImageButton and
-// TextButton.
-// Note that this type of button is not focusable by default and will not be
-// part of the focus chain. Call set_focusable(true) to make it part of the
-// focus chain.
-class VIEWS_EXPORT CustomButton : public Button,
- public ui::AnimationDelegate {
- public:
- // The menu button's class name.
- static const char kViewClassName[];
-
- virtual ~CustomButton();
-
- // Possible states
- enum ButtonState {
- BS_NORMAL = 0,
- BS_HOT,
- BS_PUSHED,
- BS_DISABLED,
- BS_COUNT
- };
-
- // Get/sets the current display state of the button.
- ButtonState state() const { return state_; }
- void SetState(ButtonState state);
-
- // Starts throbbing. See HoverAnimation for a description of cycles_til_stop.
- void StartThrobbing(int cycles_til_stop);
-
- // Stops throbbing immediately.
- void StopThrobbing();
-
- // Set how long the hover animation will last for.
- void SetAnimationDuration(int duration);
-
- void set_triggerable_event_flags(int triggerable_event_flags) {
- triggerable_event_flags_ = triggerable_event_flags;
- }
- int triggerable_event_flags() const { return triggerable_event_flags_; }
-
- // Sets whether |RequestFocus| should be invoked on a mouse press. The default
- // is true.
- void set_request_focus_on_press(bool value) {
- request_focus_on_press_ = value;
- }
- bool request_focus_on_press() const { return request_focus_on_press_; }
-
- // See description above field.
- void set_animate_on_state_change(bool value) {
- animate_on_state_change_ = value;
- }
-
- // Returns true if the mouse pointer is over this control. Note that this
- // isn't the same as IsHotTracked() because the mouse may be over the control
- // when it's disabled.
- bool IsMouseHovered() const;
-
- // Overridden from View:
- virtual void SetHotTracked(bool flag) OVERRIDE;
- virtual bool IsHotTracked() const OVERRIDE;
- virtual void OnEnabledChanged() OVERRIDE;
- virtual bool IsEnabled() const OVERRIDE;
- virtual std::string GetClassName() const OVERRIDE;
- virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
- virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseCaptureLost() OVERRIDE;
- virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE;
- virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE;
- virtual bool OnKeyReleased(const KeyEvent& event) OVERRIDE;
- virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
- virtual void ShowContextMenu(const gfx::Point& p,
- bool is_mouse_gesture) OVERRIDE;
- virtual void OnDragDone() OVERRIDE;
- virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
-
- // Overridden from ui::AnimationDelegate:
- virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
-
- protected:
- // Construct the Button with a Listener. See comment for Button's ctor.
- explicit CustomButton(ButtonListener* listener);
-
- // Invoked from SetState() when SetState() is passed a value that differs from
- // the current state. CustomButton's implementation of StateChanged() does
- // nothing; this method is provided for subclasses that wish to do something
- // on state changes.
- virtual void StateChanged();
-
- // Returns true if the event is one that can trigger notifying the listener.
- // This implementation returns true if the left mouse button is down.
- virtual bool IsTriggerableEvent(const MouseEvent& event);
-
- // Returns true if the button should become pressed when the user
- // holds the mouse down over the button. For this implementation,
- // we simply return IsTriggerableEvent(event).
- virtual bool ShouldEnterPushedState(const MouseEvent& event);
-
- // Overridden from View:
- virtual void ViewHierarchyChanged(bool is_add,
- View* parent,
- View* child) OVERRIDE;
- virtual bool IsFocusable() const OVERRIDE;
- virtual void OnBlur() OVERRIDE;
-
- // The button state (defined in implementation)
- ButtonState state_;
-
- // Hover animation.
- scoped_ptr<ui::ThrobAnimation> hover_animation_;
-
- private:
- // Should we animate when the state changes? Defaults to true.
- bool animate_on_state_change_;
-
- // Is the hover animation running because StartThrob was invoked?
- bool is_throbbing_;
-
- // Mouse event flags which can trigger button actions.
- int triggerable_event_flags_;
-
- // See description above setter.
- bool request_focus_on_press_;
-
- DISALLOW_COPY_AND_ASSIGN(CustomButton);
-};
-
-} // namespace views
-
-#endif // VIEWS_CONTROLS_BUTTON_CUSTOM_BUTTON_H_
diff --git a/views/controls/button/image_button.cc b/views/controls/button/image_button.cc
deleted file mode 100644
index 8379b41..0000000
--- a/views/controls/button/image_button.cc
+++ /dev/null
@@ -1,174 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "views/controls/button/image_button.h"
-
-#include "base/utf_string_conversions.h"
-#include "ui/base/animation/throb_animation.h"
-#include "ui/gfx/canvas.h"
-#include "ui/gfx/skbitmap_operations.h"
-
-namespace views {
-
-static const int kDefaultWidth = 16; // Default button width if no theme.
-static const int kDefaultHeight = 14; // Default button height if no theme.
-
-////////////////////////////////////////////////////////////////////////////////
-// ImageButton, public:
-
-ImageButton::ImageButton(ButtonListener* listener)
- : CustomButton(listener),
- h_alignment_(ALIGN_LEFT),
- v_alignment_(ALIGN_TOP),
- preferred_size_(kDefaultWidth, kDefaultHeight) {
- // By default, we request that the gfx::Canvas passed to our View::OnPaint()
- // implementation is flipped horizontally so that the button's bitmaps are
- // mirrored when the UI directionality is right-to-left.
- EnableCanvasFlippingForRTLUI(true);
-}
-
-ImageButton::~ImageButton() {
-}
-
-void ImageButton::SetImage(ButtonState aState, const SkBitmap* anImage) {
- images_[aState] = anImage ? *anImage : SkBitmap();
- PreferredSizeChanged();
-}
-
-void ImageButton::SetBackground(SkColor color,
- const SkBitmap* image,
- const SkBitmap* mask) {
- if (!image || !mask) {
- background_image_.reset();
- return;
- }
-
- background_image_ =
- SkBitmapOperations::CreateButtonBackground(color, *image, *mask);
-}
-
-void ImageButton::SetImageAlignment(HorizontalAlignment h_align,
- VerticalAlignment v_align) {
- h_alignment_ = h_align;
- v_alignment_ = v_align;
- SchedulePaint();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ImageButton, View overrides:
-
-gfx::Size ImageButton::GetPreferredSize() {
- if (!images_[BS_NORMAL].isNull())
- return gfx::Size(images_[BS_NORMAL].width(), images_[BS_NORMAL].height());
- return preferred_size_;
-}
-
-void ImageButton::OnPaint(gfx::Canvas* canvas) {
- // Call the base class first to paint any background/borders.
- View::OnPaint(canvas);
-
- SkBitmap img = GetImageToPaint();
-
- if (!img.isNull()) {
- int x = 0, y = 0;
-
- if (h_alignment_ == ALIGN_CENTER)
- x = (width() - img.width()) / 2;
- else if (h_alignment_ == ALIGN_RIGHT)
- x = width() - img.width();
-
- if (v_alignment_ == ALIGN_MIDDLE)
- y = (height() - img.height()) / 2;
- else if (v_alignment_ == ALIGN_BOTTOM)
- y = height() - img.height();
-
- if (!background_image_.empty())
- canvas->DrawBitmapInt(background_image_, x, y);
- canvas->DrawBitmapInt(img, x, y);
- }
- OnPaintFocusBorder(canvas);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ImageButton, protected:
-
-SkBitmap ImageButton::GetImageToPaint() {
- SkBitmap img;
-
- if (!images_[BS_HOT].isNull() && hover_animation_->is_animating()) {
- img = SkBitmapOperations::CreateBlendedBitmap(images_[BS_NORMAL],
- images_[BS_HOT], hover_animation_->GetCurrentValue());
- } else {
- img = images_[state_];
- }
-
- return !img.isNull() ? img : images_[BS_NORMAL];
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ToggleImageButton, public:
-
-ToggleImageButton::ToggleImageButton(ButtonListener* listener)
- : ImageButton(listener),
- toggled_(false) {
-}
-
-ToggleImageButton::~ToggleImageButton() {
-}
-
-void ToggleImageButton::SetToggled(bool toggled) {
- if (toggled == toggled_)
- return;
-
- for (int i = 0; i < BS_COUNT; ++i) {
- SkBitmap temp = images_[i];
- images_[i] = alternate_images_[i];
- alternate_images_[i] = temp;
- }
- toggled_ = toggled;
- SchedulePaint();
-}
-
-void ToggleImageButton::SetToggledImage(ButtonState state,
- const SkBitmap* image) {
- if (toggled_) {
- images_[state] = image ? *image : SkBitmap();
- if (state_ == state)
- SchedulePaint();
- } else {
- alternate_images_[state] = image ? *image : SkBitmap();
- }
-}
-
-void ToggleImageButton::SetToggledTooltipText(const string16& tooltip) {
- toggled_tooltip_text_ = tooltip;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ToggleImageButton, ImageButton overrides:
-
-void ToggleImageButton::SetImage(ButtonState state, const SkBitmap* image) {
- if (toggled_) {
- alternate_images_[state] = image ? *image : SkBitmap();
- } else {
- images_[state] = image ? *image : SkBitmap();
- if (state_ == state)
- SchedulePaint();
- }
- PreferredSizeChanged();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ToggleImageButton, View overrides:
-
-bool ToggleImageButton::GetTooltipText(const gfx::Point& p,
- string16* tooltip) const {
- if (!toggled_ || toggled_tooltip_text_.empty())
- return Button::GetTooltipText(p, tooltip);
-
- *tooltip = toggled_tooltip_text_;
- return true;
-}
-
-} // namespace views
diff --git a/views/controls/button/image_button.h b/views/controls/button/image_button.h
deleted file mode 100644
index 2ba26fa..0000000
--- a/views/controls/button/image_button.h
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_
-#define VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_
-#pragma once
-
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "views/controls/button/custom_button.h"
-
-namespace views {
-
-// An image button.
-
-// Note that this type of button is not focusable by default and will not be
-// part of the focus chain. Call set_focusable(true) to make it part of the
-// focus chain.
-
-class VIEWS_EXPORT ImageButton : public CustomButton {
- public:
- explicit ImageButton(ButtonListener* listener);
- virtual ~ImageButton();
-
- // Set the image the button should use for the provided state.
- virtual void SetImage(ButtonState aState, const SkBitmap* anImage);
-
- // Set the background details.
- void SetBackground(SkColor color,
- const SkBitmap* image,
- const SkBitmap* mask);
-
- enum HorizontalAlignment { ALIGN_LEFT = 0,
- ALIGN_CENTER,
- ALIGN_RIGHT, };
-
- enum VerticalAlignment { ALIGN_TOP = 0,
- ALIGN_MIDDLE,
- ALIGN_BOTTOM };
-
- // Sets how the image is laid out within the button's bounds.
- void SetImageAlignment(HorizontalAlignment h_align,
- VerticalAlignment v_align);
-
- // Overridden from View:
- virtual gfx::Size GetPreferredSize() OVERRIDE;
- virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
-
- // Sets preferred size, so it could be correctly positioned in layout even if
- // it is NULL.
- void SetPreferredSize(const gfx::Size& preferred_size) {
- preferred_size_ = preferred_size;
- }
-
- protected:
- // Returns the image to paint. This is invoked from paint and returns a value
- // from images.
- virtual SkBitmap GetImageToPaint();
-
- // The images used to render the different states of this button.
- SkBitmap images_[BS_COUNT];
-
- // The background image.
- SkBitmap background_image_;
-
- private:
- // Image alignment.
- HorizontalAlignment h_alignment_;
- VerticalAlignment v_alignment_;
- gfx::Size preferred_size_;
-
- DISALLOW_COPY_AND_ASSIGN(ImageButton);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// ToggleImageButton
-//
-// A toggle-able ImageButton. It swaps out its graphics when toggled.
-//
-////////////////////////////////////////////////////////////////////////////////
-class VIEWS_EXPORT ToggleImageButton : public ImageButton {
- public:
- explicit ToggleImageButton(ButtonListener* listener);
- virtual ~ToggleImageButton();
-
- // Change the toggled state.
- void SetToggled(bool toggled);
-
- // Like ImageButton::SetImage(), but to set the graphics used for the
- // "has been toggled" state. Must be called for each button state
- // before the button is toggled.
- void SetToggledImage(ButtonState state, const SkBitmap* image);
-
- // Set the tooltip text displayed when the button is toggled.
- void SetToggledTooltipText(const string16& tooltip);
-
- // Overridden from ImageButton:
- virtual void SetImage(ButtonState aState, const SkBitmap* anImage) OVERRIDE;
-
- // Overridden from View:
- virtual bool GetTooltipText(const gfx::Point& p,
- string16* tooltip) const OVERRIDE;
-
- private:
- // The parent class's images_ member is used for the current images,
- // and this array is used to hold the alternative images.
- // We swap between the two when toggling.
- SkBitmap alternate_images_[BS_COUNT];
-
- // True if the button is currently toggled.
- bool toggled_;
-
- // The parent class's tooltip_text_ is displayed when not toggled, and
- // this one is shown when toggled.
- string16 toggled_tooltip_text_;
-
- DISALLOW_COPY_AND_ASSIGN(ToggleImageButton);
-};
-
-} // namespace views
-
-#endif // VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_
diff --git a/views/controls/button/menu_button.cc b/views/controls/button/menu_button.cc
deleted file mode 100644
index 0248aaf..0000000
--- a/views/controls/button/menu_button.cc
+++ /dev/null
@@ -1,263 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "views/controls/button/menu_button.h"
-
-#include "base/utf_string_conversions.h"
-#include "grit/ui_resources.h"
-#include "grit/ui_strings.h"
-#include "ui/base/accessibility/accessible_view_state.h"
-#include "ui/base/dragdrop/drag_drop_types.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/canvas.h"
-#include "ui/gfx/screen.h"
-#include "ui/views/events/event.h"
-#include "ui/views/widget/root_view.h"
-#include "ui/views/widget/widget.h"
-#include "views/controls/button/button.h"
-#include "views/controls/menu/view_menu_delegate.h"
-
-using base::Time;
-using base::TimeDelta;
-
-namespace views {
-
-// The amount of time, in milliseconds, we wait before allowing another mouse
-// pressed event to show the menu.
-static const int64 kMinimumTimeBetweenButtonClicks = 100;
-
-// How much padding to put on the left and right of the menu marker.
-static const int kMenuMarkerPaddingLeft = 3;
-static const int kMenuMarkerPaddingRight = -1;
-
-// Default menu offset.
-static const int kDefaultMenuOffsetX = -2;
-static const int kDefaultMenuOffsetY = -4;
-
-// static
-const char MenuButton::kViewClassName[] = "views/MenuButton";
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// MenuButton - constructors, destructors, initialization
-//
-////////////////////////////////////////////////////////////////////////////////
-
-MenuButton::MenuButton(ButtonListener* listener,
- const string16& text,
- ViewMenuDelegate* menu_delegate,
- bool show_menu_marker)
- : TextButton(listener, text),
- menu_visible_(false),
- menu_offset_(kDefaultMenuOffsetX, kDefaultMenuOffsetY),
- menu_delegate_(menu_delegate),
- show_menu_marker_(show_menu_marker),
- menu_marker_(ResourceBundle::GetSharedInstance().GetBitmapNamed(
- IDR_MENU_DROPARROW)),
- destroyed_flag_(NULL) {
- set_alignment(TextButton::ALIGN_LEFT);
-}
-
-MenuButton::~MenuButton() {
- if (destroyed_flag_)
- *destroyed_flag_ = true;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// MenuButton - Public APIs
-//
-////////////////////////////////////////////////////////////////////////////////
-
-bool MenuButton::Activate() {
- SetState(BS_PUSHED);
- if (menu_delegate_) {
- gfx::Rect lb = GetLocalBounds();
-
- // The position of the menu depends on whether or not the locale is
- // right-to-left.
- gfx::Point menu_position(lb.right(), lb.bottom());
- if (base::i18n::IsRTL())
- menu_position.set_x(lb.x());
-
- View::ConvertPointToScreen(this, &menu_position);
- if (base::i18n::IsRTL())
- menu_position.Offset(-menu_offset_.x(), menu_offset_.y());
- else
- menu_position.Offset(menu_offset_.x(), menu_offset_.y());
-
- int max_x_coordinate = GetMaximumScreenXCoordinate();
- if (max_x_coordinate && max_x_coordinate <= menu_position.x())
- menu_position.set_x(max_x_coordinate - 1);
-
- // We're about to show the menu from a mouse press. By showing from the
- // mouse press event we block RootView in mouse dispatching. This also
- // appears to cause RootView to get a mouse pressed BEFORE the mouse
- // release is seen, which means RootView sends us another mouse press no
- // matter where the user pressed. To force RootView to recalculate the
- // mouse target during the mouse press we explicitly set the mouse handler
- // to NULL.
- static_cast<internal::RootView*>(GetWidget()->GetRootView())->
- SetMouseHandler(NULL);
-
- menu_visible_ = true;
-
- bool destroyed = false;
- destroyed_flag_ = &destroyed;
-
- menu_delegate_->RunMenu(this, menu_position);
-
- if (destroyed) {
- // The menu was deleted while showing. Don't attempt any processing.
- return false;
- }
-
- destroyed_flag_ = NULL;
-
- menu_visible_ = false;
- menu_closed_time_ = Time::Now();
-
- // Now that the menu has closed, we need to manually reset state to
- // "normal" since the menu modal loop will have prevented normal
- // mouse move messages from getting to this View. We set "normal"
- // and not "hot" because the likelihood is that the mouse is now
- // somewhere else (user clicked elsewhere on screen to close the menu
- // or selected an item) and we will inevitably refresh the hot state
- // in the event the mouse _is_ over the view.
- SetState(BS_NORMAL);
-
- // We must return false here so that the RootView does not get stuck
- // sending all mouse pressed events to us instead of the appropriate
- // target.
- return false;
- }
- return true;
-}
-
-void MenuButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
- TextButton::PaintButton(canvas, mode);
-
- if (show_menu_marker_) {
- gfx::Insets insets = GetInsets();
-
- // We can not use the views' mirroring infrastructure for mirroring a
- // MenuButton control (see TextButton::OnPaint() for a detailed explanation
- // regarding why we can not flip the canvas). Therefore, we need to
- // manually mirror the position of the down arrow.
- gfx::Rect arrow_bounds(width() - insets.right() -
- menu_marker_->width() - kMenuMarkerPaddingRight,
- height() / 2 - menu_marker_->height() / 2,
- menu_marker_->width(),
- menu_marker_->height());
- arrow_bounds.set_x(GetMirroredXForRect(arrow_bounds));
- canvas->DrawBitmapInt(*menu_marker_, arrow_bounds.x(), arrow_bounds.y());
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// MenuButton - Events
-//
-////////////////////////////////////////////////////////////////////////////////
-
-gfx::Size MenuButton::GetPreferredSize() {
- gfx::Size prefsize = TextButton::GetPreferredSize();
- if (show_menu_marker_) {
- prefsize.Enlarge(menu_marker_->width() + kMenuMarkerPaddingLeft +
- kMenuMarkerPaddingRight,
- 0);
- }
- return prefsize;
-}
-
-std::string MenuButton::GetClassName() const {
- return kViewClassName;
-}
-
-bool MenuButton::OnMousePressed(const MouseEvent& event) {
- RequestFocus();
- if (state() != BS_DISABLED) {
- // If we're draggable (GetDragOperations returns a non-zero value), then
- // don't pop on press, instead wait for release.
- if (event.IsOnlyLeftMouseButton() && HitTest(event.location()) &&
- GetDragOperations(event.location()) == ui::DragDropTypes::DRAG_NONE) {
- TimeDelta delta = Time::Now() - menu_closed_time_;
- int64 delta_in_milliseconds = delta.InMilliseconds();
- if (delta_in_milliseconds > kMinimumTimeBetweenButtonClicks) {
- return Activate();
- }
- }
- }
- return true;
-}
-
-void MenuButton::OnMouseReleased(const MouseEvent& event) {
- // Explicitly test for left mouse button to show the menu. If we tested for
- // !IsTriggerableEvent it could lead to a situation where we end up showing
- // the menu and context menu (this would happen if the right button is not
- // triggerable and there's a context menu).
- if (GetDragOperations(event.location()) != ui::DragDropTypes::DRAG_NONE &&
- state() != BS_DISABLED && !InDrag() && event.IsOnlyLeftMouseButton() &&
- HitTest(event.location())) {
- Activate();
- } else {
- TextButton::OnMouseReleased(event);
- }
-}
-
-// The reason we override View::OnMouseExited is because we get this event when
-// we display the menu. If we don't override this method then
-// BaseButton::OnMouseExited will get the event and will set the button's state
-// to BS_NORMAL instead of keeping the state BM_PUSHED. This, in turn, will
-// cause the button to appear depressed while the menu is displayed.
-void MenuButton::OnMouseExited(const MouseEvent& event) {
- if ((state_ != BS_DISABLED) && (!menu_visible_) && (!InDrag())) {
- SetState(BS_NORMAL);
- }
-}
-
-bool MenuButton::OnKeyPressed(const KeyEvent& event) {
- switch (event.key_code()) {
- case ui::VKEY_SPACE:
- // Alt-space on windows should show the window menu.
- if (event.IsAltDown())
- break;
- case ui::VKEY_RETURN:
- case ui::VKEY_UP:
- case ui::VKEY_DOWN: {
- // WARNING: we may have been deleted by the time Activate returns.
- return Activate();
- }
- default:
- break;
- }
- return false;
-}
-
-bool MenuButton::OnKeyReleased(const KeyEvent& event) {
- // Override CustomButton's implementation, which presses the button when
- // you press space and clicks it when you release space. For a MenuButton
- // we always activate the menu on key press.
- return false;
-}
-
-void MenuButton::GetAccessibleState(ui::AccessibleViewState* state) {
- CustomButton::GetAccessibleState(state);
- state->role = ui::AccessibilityTypes::ROLE_BUTTONMENU;
- state->default_action = l10n_util::GetStringUTF16(IDS_APP_ACCACTION_PRESS);
- state->state = ui::AccessibilityTypes::STATE_HASPOPUP;
-}
-
-int MenuButton::GetMaximumScreenXCoordinate() {
- if (!GetWidget()) {
- NOTREACHED();
- return 0;
- }
-
- gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen();
- return monitor_bounds.right() - 1;
-}
-
-} // namespace views
diff --git a/views/controls/button/menu_button.h b/views/controls/button/menu_button.h
deleted file mode 100644
index 5f202cb..0000000
--- a/views/controls/button/menu_button.h
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_
-#define VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_
-#pragma once
-
-#include <string>
-
-#include "base/string16.h"
-#include "base/time.h"
-#include "ui/gfx/font.h"
-#include "views/background.h"
-#include "views/controls/button/text_button.h"
-
-namespace views {
-
-class MouseEvent;
-class ViewMenuDelegate;
-
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// MenuButton
-//
-// A button that shows a menu when the left mouse button is pushed
-//
-////////////////////////////////////////////////////////////////////////////////
-class VIEWS_EXPORT MenuButton : public TextButton {
- public:
- static const char kViewClassName[];
-
- // Create a Button.
- MenuButton(ButtonListener* listener,
- const string16& text,
- ViewMenuDelegate* menu_delegate,
- bool show_menu_marker);
- virtual ~MenuButton();
-
- void set_menu_marker(const SkBitmap* menu_marker) {
- menu_marker_ = menu_marker;
- }
-
- const gfx::Point& menu_offset() const { return menu_offset_; }
- void set_menu_offset(int x, int y) { menu_offset_.SetPoint(x, y); }
-
- // Activate the button (called when the button is pressed).
- virtual bool Activate();
-
- // Overridden from TextButton for the potential use of a drop marker.
- virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) OVERRIDE;
-
- // Overridden from View:
- virtual gfx::Size GetPreferredSize() OVERRIDE;
- virtual std::string GetClassName() const OVERRIDE;
- virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseReleased(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
- virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE;
- virtual bool OnKeyReleased(const KeyEvent& event) OVERRIDE;
- virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
-
- protected:
- // True if the menu is currently visible.
- bool menu_visible_;
-
- // Offset of the associated menu position.
- gfx::Point menu_offset_;
-
- private:
- friend class TextButtonBackground;
-
- // Compute the maximum X coordinate for the current screen. MenuButtons
- // use this to make sure a menu is never shown off screen.
- int GetMaximumScreenXCoordinate();
-
- // We use a time object in order to keep track of when the menu was closed.
- // The time is used for simulating menu behavior for the menu button; that
- // is, if the menu is shown and the button is pressed, we need to close the
- // menu. There is no clean way to get the second click event because the
- // menu is displayed using a modal loop and, unlike regular menus in Windows,
- // the button is not part of the displayed menu.
- base::Time menu_closed_time_;
-
- // The associated menu's resource identifier.
- ViewMenuDelegate* menu_delegate_;
-
- // Whether or not we're showing a drop marker.
- bool show_menu_marker_;
-
- // The down arrow used to differentiate the menu button from normal
- // text buttons.
- const SkBitmap* menu_marker_;
-
- // If non-null the destuctor sets this to true. This is set while the menu is
- // showing and used to detect if the menu was deleted while running.
- bool* destroyed_flag_;
-
- DISALLOW_COPY_AND_ASSIGN(MenuButton);
-};
-
-} // namespace views
-
-#endif // VIEWS_CONTROLS_BUTTON_MENU_BUTTON_H_
diff --git a/views/controls/button/radio_button.cc b/views/controls/button/radio_button.cc
deleted file mode 100644
index 8cd1c4a..0000000
--- a/views/controls/button/radio_button.cc
+++ /dev/null
@@ -1,104 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "views/controls/button/radio_button.h"
-
-#include "base/logging.h"
-#include "ui/base/accessibility/accessible_view_state.h"
-#include "ui/views/widget/widget.h"
-
-namespace views {
-
-// static
-const char RadioButton::kViewClassName[] = "views/RadioButton";
-
-RadioButton::RadioButton(const string16& label, int group_id)
- : Checkbox(label) {
- SetGroup(group_id);
- set_focusable(true);
-}
-
-RadioButton::~RadioButton() {
-}
-
-void RadioButton::SetChecked(bool checked) {
- if (checked == RadioButton::checked())
- return;
- if (checked) {
- // We can't just get the root view here because sometimes the radio
- // button isn't attached to a root view (e.g., if it's part of a tab page
- // that is currently not active).
- View* container = parent();
- while (container && container->parent())
- container = container->parent();
- if (container) {
- Views other;
- container->GetViewsInGroup(GetGroup(), &other);
- for (Views::iterator i(other.begin()); i != other.end(); ++i) {
- if (*i != this) {
- if ((*i)->GetClassName() != kViewClassName) {
- NOTREACHED() << "radio-button-nt has same group as other non "
- "radio-button-nt views.";
- continue;
- }
- RadioButton* peer = static_cast<RadioButton*>(*i);
- peer->SetChecked(false);
- }
- }
- }
- }
- Checkbox::SetChecked(checked);
-}
-
-std::string RadioButton::GetClassName() const {
- return kViewClassName;
-}
-
-void RadioButton::GetAccessibleState(ui::AccessibleViewState* state) {
- Checkbox::GetAccessibleState(state);
- state->role = ui::AccessibilityTypes::ROLE_RADIOBUTTON;
-}
-
-View* RadioButton::GetSelectedViewForGroup(int group) {
- Views views;
- GetWidget()->GetRootView()->GetViewsInGroup(group, &views);
- if (views.empty())
- return NULL;
-
- for (Views::const_iterator i(views.begin()); i != views.end(); ++i) {
- // REVIEW: why don't we check the runtime type like is done above?
- RadioButton* radio_button = static_cast<RadioButton*>(*i);
- if (radio_button->checked())
- return radio_button;
- }
- return NULL;
-}
-
-bool RadioButton::IsGroupFocusTraversable() const {
- // When focusing a radio button with tab/shift+tab, only the selected button
- // from the group should be focused.
- return false;
-}
-
-void RadioButton::OnFocus() {
- Checkbox::OnFocus();
- SetChecked(true);
- views::MouseEvent event(ui::ET_MOUSE_PRESSED, 0, 0, 0);
- TextButtonBase::NotifyClick(event);
-}
-
-void RadioButton::NotifyClick(const views::Event& event) {
- // Set the checked state to true only if we are unchecked, since we can't
- // be toggled on and off like a checkbox.
- if (!checked())
- SetChecked(true);
- RequestFocus();
- TextButtonBase::NotifyClick(event);
-}
-
-gfx::NativeTheme::Part RadioButton::GetThemePart() const {
- return gfx::NativeTheme::kRadio;
-}
-
-} // namespace views
diff --git a/views/controls/button/radio_button.h b/views/controls/button/radio_button.h
deleted file mode 100644
index f3a1195..0000000
--- a/views/controls/button/radio_button.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef VIEWS_CONTROLS_BUTTON_RADIO_BUTTON_H_
-#define VIEWS_CONTROLS_BUTTON_RADIO_BUTTON_H_
-#pragma once
-
-#include "base/string16.h"
-#include "views/controls/button/checkbox.h"
-
-namespace views {
-
-// A native themed class representing a radio button. This class does not use
-// platform specific objects to replicate the native platforms looks and feel.
-class VIEWS_EXPORT RadioButton : public Checkbox {
- public:
- // The button's class name.
- static const char kViewClassName[];
-
- RadioButton(const string16& label, int group_id);
- virtual ~RadioButton();
-
- // Overridden from View:
- virtual std::string GetClassName() const OVERRIDE;
- virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
- virtual View* GetSelectedViewForGroup(int group) OVERRIDE;
- virtual bool IsGroupFocusTraversable() const OVERRIDE;
- virtual void OnFocus() OVERRIDE;
-
- // Overridden from Button:
- virtual void NotifyClick(const views::Event& event) OVERRIDE;
-
- // Overridden from TextButtonBase:
- virtual gfx::NativeTheme::Part GetThemePart() const OVERRIDE;
-
- // Overridden from Checkbox:
- virtual void SetChecked(bool checked) OVERRIDE;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(RadioButton);
-};
-
-} // namespace views
-
-#endif // VIEWS_CONTROLS_BUTTON_RADIO_BUTTON_H_
diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc
deleted file mode 100644
index 3456f84..0000000
--- a/views/controls/button/text_button.cc
+++ /dev/null
@@ -1,860 +0,0 @@
-// Copyright (c) 2011 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.
-
-#include "views/controls/button/text_button.h"
-
-#include <algorithm>
-
-#include "base/logging.h"
-#include "grit/ui_resources.h"
-#include "ui/base/animation/throb_animation.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/canvas_skia.h"
-#include "ui/views/events/event.h"
-#include "ui/views/widget/widget.h"
-#include "views/controls/button/button.h"
-
-#if defined(OS_WIN)
-#include "skia/ext/skia_utils_win.h"
-#include "ui/gfx/native_theme_win.h"
-#include "ui/gfx/platform_font_win.h"
-#endif
-
-namespace views {
-
-#if defined(OS_WIN)
-// The min size in DLUs comes from
-// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwue/html/ch14e.asp
-static const int kMinWidthDLUs = 50;
-static const int kMinHeightDLUs = 14;
-#endif
-
-
-// Default space between the icon and text.
-static const int kDefaultIconTextSpacing = 5;
-
-// Preferred padding between text and edge.
-static const int kPreferredPaddingHorizontal = 6;
-static const int kPreferredPaddingVertical = 5;
-
-// Preferred padding between text and edge for NativeTheme border.
-static const int kPreferredNativeThemePaddingHorizontal = 12;
-static const int kPreferredNativeThemePaddingVertical = 5;
-
-// By default the focus rect is drawn at the border of the view.
-// For a button, we inset the focus rect by 3 pixels so that it
-// doesn't draw on top of the button's border. This roughly matches
-// how the Windows native focus rect for buttons looks. A subclass
-// that draws a button with different padding may need to
-// override OnPaintFocusBorder and do something different.
-static const int kFocusRectInset = 3;
-
-// Default background color for buttons.
-const SkColor kBackgroundColor = SkColorSetRGB(0xde, 0xde, 0xde);
-
-#if defined(USE_AURA)
-// static
-const SkColor TextButtonBase::kEnabledColor = SkColorSetRGB(0x44, 0x44, 0x44);
-// static
-const SkColor TextButtonBase::kHighlightColor = SkColorSetRGB(0, 0, 0);
-// static
-const SkColor TextButtonBase::kDisabledColor = SkColorSetRGB(0x99, 0x99, 0x99);
-// static
-const SkColor TextButtonBase::kHoverColor = TextButton::kEnabledColor;
-#else // !defined(USE_AURA)
-// static
-const SkColor TextButtonBase::kEnabledColor = SkColorSetRGB(6, 45, 117);
-// static
-const SkColor TextButtonBase::kHighlightColor =
- SkColorSetARGB(200, 255, 255, 255);
-// static
-const SkColor TextButtonBase::kDisabledColor = SkColorSetRGB(161, 161, 146);
-// static
-const SkColor TextButtonBase::kHoverColor = TextButton::kEnabledColor;
-#endif // defined(USE_AURA)
-
-// How long the hover fade animation should last.
-static const int kHoverAnimationDurationMs = 170;
-
-// static
-const char TextButtonBase::kViewClassName[] = "views/TextButtonBase";
-// static
-const char TextButton::kViewClassName[] = "views/TextButton";
-// static
-const char NativeTextButton::kViewClassName[] = "views/NativeTextButton";
-
-static int PrefixTypeToCanvasType(TextButton::PrefixType type) {
- switch (type) {
- case TextButton::PREFIX_HIDE:
- return gfx::Canvas::HIDE_PREFIX;
- case TextButton::PREFIX_SHOW:
- return gfx::Canvas::SHOW_PREFIX;
- case TextButton::PREFIX_NONE:
- return 0;
- default:
- NOTREACHED();
- return 0;
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// TextButtonBorder - constructors, destructors, initialization
-//
-////////////////////////////////////////////////////////////////////////////////
-
-TextButtonBorder::TextButtonBorder()
- : vertical_padding_(kPreferredPaddingVertical) {
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- BorderImageSet normal_set = {
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- };
- set_normal_set(normal_set);
-
- BorderImageSet hot_set = {
- rb.GetBitmapNamed(IDR_TEXTBUTTON_TOP_LEFT_H),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_TOP_H),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_TOP_RIGHT_H),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_LEFT_H),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_CENTER_H),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_RIGHT_H),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_BOTTOM_LEFT_H),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_BOTTOM_H),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_BOTTOM_RIGHT_H),
- };
- set_hot_set(hot_set);
-
- BorderImageSet pushed_set = {
- rb.GetBitmapNamed(IDR_TEXTBUTTON_TOP_LEFT_P),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_TOP_P),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_TOP_RIGHT_P),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_LEFT_P),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_CENTER_P),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_RIGHT_P),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_BOTTOM_LEFT_P),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_BOTTOM_P),
- rb.GetBitmapNamed(IDR_TEXTBUTTON_BOTTOM_RIGHT_P),
- };
- set_pushed_set(pushed_set);
-}
-
-TextButtonBorder::~TextButtonBorder() {
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// TextButtonBorder - painting
-//
-////////////////////////////////////////////////////////////////////////////////
-void TextButtonBorder::Paint(const View& view, gfx::Canvas* canvas) const {
- const TextButton* button = static_cast<const TextButton*>(&view);
- int state = button->state();
-
- const BorderImageSet* set = &normal_set_;
- if (button->show_multiple_icon_states() &&
- ((state == TextButton::BS_HOT) || (state == TextButton::BS_PUSHED)))
- set = (state == TextButton::BS_HOT) ? &hot_set_ : &pushed_set_;
- if (set->top_left) {
- if (button->GetAnimation()->is_animating()) {
- // TODO(pkasting): Really this should crossfade between states so it could
- // handle the case of having a non-NULL |normal_set_|.
- canvas->SaveLayerAlpha(static_cast<uint8>(
- button->GetAnimation()->CurrentValueBetween(0, 255)));
- canvas->GetSkCanvas()->drawARGB(0, 255, 255, 255,
- SkXfermode::kClear_Mode);
- Paint(view, canvas, *set);
- canvas->Restore();
- } else {
- Paint(view, canvas, *set);
- }
- }
-}
-
-void TextButtonBorder::Paint(const View& view,
- gfx::Canvas* canvas,
- const BorderImageSet& set) const {
- DCHECK(set.top_left);
- int width = view.bounds().width();
- int height = view.bounds().height();
- int tl_width = set.top_left->width();
- int tl_height = set.top_left->height();
- int t_height = set.top->height();
- int tr_height = set.top_right->height();
- int l_width = set.left->width();
- int r_width = set.right->width();
- int bl_width = set.bottom_left->width();
- int bl_height = set.bottom_left->height();
- int b_height = set.bottom->height();
- int br_width = set.bottom_right->width();
- int br_height = set.bottom_right->height();
-
- canvas->DrawBitmapInt(*set.top_left, 0, 0);
- canvas->DrawBitmapInt(*set.top, 0, 0, set.top->width(), t_height, tl_width, 0,
- width - tl_width - set.top_right->width(), t_height, false);
- canvas->DrawBitmapInt(*set.top_right, width - set.top_right->width(), 0);
- canvas->DrawBitmapInt(*set.left, 0, 0, l_width, set.left->height(), 0,
- tl_height, tl_width, height - tl_height - bl_height, false);
- canvas->DrawBitmapInt(*set.center, 0, 0, set.center->width(),
- set.center->height(), l_width, t_height, width - l_width - r_width,
- height - t_height - b_height, false);
- canvas->DrawBitmapInt(*set.right, 0, 0, r_width, set.right->height(),
- width - r_width, tr_height, r_width,
- height - tr_height - br_height, false);
- canvas->DrawBitmapInt(*set.bottom_left, 0, height - bl_height);
- canvas->DrawBitmapInt(*set.bottom, 0, 0, set.bottom->width(), b_height,
- bl_width, height - b_height,
- width - bl_width - br_width, b_height, false);
- canvas->DrawBitmapInt(*set.bottom_right, width - br_width,
- height - br_height);
-}
-
-void TextButtonBorder::GetInsets(gfx::Insets* insets) const {
- insets->Set(vertical_padding_, kPreferredPaddingHorizontal,
- vertical_padding_, kPreferredPaddingHorizontal);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// TextButtonNativeThemeBorder
-//
-////////////////////////////////////////////////////////////////////////////////
-
-TextButtonNativeThemeBorder::TextButtonNativeThemeBorder(
- NativeThemeDelegate* delegate)
- : delegate_(delegate) {
-}
-
-TextButtonNativeThemeBorder::~TextButtonNativeThemeBorder() {
-}
-
-void TextButtonNativeThemeBorder::Paint(const View& view,
- gfx::Canvas* canvas) const {
- const TextButtonBase* tb = static_cast<const TextButton*>(&view);
- const gfx::NativeTheme* native_theme = gfx::NativeTheme::instance();
- gfx::NativeTheme::Part part = delegate_->GetThemePart();
- gfx::Rect rect(delegate_->GetThemePaintRect());
-
- if (tb->show_multiple_icon_states() &&
- delegate_->GetThemeAnimation() != NULL &&
- delegate_->GetThemeAnimation()->is_animating()) {
- // Paint background state.
- gfx::NativeTheme::ExtraParams prev_extra;
- gfx::NativeTheme::State prev_state =
- delegate_->GetBackgroundThemeState(&prev_extra);
- native_theme->Paint(
- canvas->GetSkCanvas(), part, prev_state, rect, prev_extra);
-
- // Composite foreground state above it.
- gfx::NativeTheme::ExtraParams extra;
- gfx::NativeTheme::State state = delegate_->GetForegroundThemeState(&extra);
- int alpha = delegate_->GetThemeAnimation()->CurrentValueBetween(0, 255);
- canvas->SaveLayerAlpha(static_cast<uint8>(alpha));
- native_theme->Paint(canvas->GetSkCanvas(), part, state, rect, extra);
- canvas->Restore();
- } else {
- gfx::NativeTheme::ExtraParams extra;
- gfx::NativeTheme::State state = delegate_->GetThemeState(&extra);
- native_theme->Paint(canvas->GetSkCanvas(), part, state, rect, extra);
- }
-}
-
-void TextButtonNativeThemeBorder::GetInsets(gfx::Insets* insets) const {
- insets->Set(kPreferredNativeThemePaddingVertical,
- kPreferredNativeThemePaddingHorizontal,
- kPreferredNativeThemePaddingVertical,
- kPreferredNativeThemePaddingHorizontal);
-}
-
-
-////////////////////////////////////////////////////////////////////////////////
-// TextButtonBase, public:
-
-TextButtonBase::TextButtonBase(ButtonListener* listener, const string16& text)
- : CustomButton(listener),
- alignment_(ALIGN_LEFT),
- font_(ResourceBundle::GetSharedInstance().GetFont(
- ResourceBundle::BaseFont)),
- color_(kEnabledColor),
- color_enabled_(kEnabledColor),
- color_disabled_(kDisabledColor),
- color_highlight_(kHighlightColor),
- color_hover_(kHoverColor),
- text_halo_color_(0),
- has_text_halo_(false),
- active_text_shadow_color_(0),
- inactive_text_shadow_color_(0),
- has_shadow_(false),
- shadow_offset_(gfx::Point(1, 1)),
- max_width_(0),
- show_multiple_icon_states_(true),
- is_default_(false),
- multi_line_(false),
- prefix_type_(PREFIX_NONE) {
- SetText(text);
- SetAnimationDuration(kHoverAnimationDurationMs);
-}
-
-TextButtonBase::~TextButtonBase() {
-}
-
-void TextButtonBase::SetIsDefault(bool is_default) {
- if (is_default == is_default_)
- return;
- is_default_ = is_default;
- if (is_default_)
- AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, false, false, false));
- else
- RemoveAccelerator(ui::Accelerator(ui::VKEY_RETURN, false, false, false));
- SchedulePaint();
-}
-
-void TextButtonBase::SetText(const string16& text) {
- text_ = text;
- SetAccessibleName(text);
- UpdateTextSize();
-}
-
-void TextButtonBase::SetFont(const gfx::Font& font) {
- font_ = font;
- UpdateTextSize();
-}
-
-void TextButtonBase::SetEnabledColor(SkColor color) {
- color_enabled_ = color;
- UpdateColor();
-}
-
-void TextButtonBase::SetDisabledColor(SkColor color) {
- color_disabled_ = color;
- UpdateColor();
-}
-
-void TextButtonBase::SetHighlightColor(SkColor color) {
- color_highlight_ = color;
-}
-
-void TextButtonBase::SetHoverColor(SkColor color) {
- color_hover_ = color;
-}
-
-void TextButtonBase::SetTextHaloColor(SkColor color) {
- text_halo_color_ = color;
- has_text_halo_ = true;
-}
-
-void TextButtonBase::SetTextShadowColors(SkColor active_color,
- SkColor inactive_color) {
- active_text_shadow_color_ = active_color;
- inactive_text_shadow_color_ = inactive_color;
- has_shadow_ = true;
-}
-
-void TextButtonBase::SetTextShadowOffset(int x, int y) {
- shadow_offset_.SetPoint(x, y);
-}
-
-void TextButtonBase::ClearMaxTextSize() {
- max_text_size_ = text_size_;
-}
-
-void TextButtonBase::SetShowMultipleIconStates(bool show_multiple_icon_states) {
- show_multiple_icon_states_ = show_multiple_icon_states;
-}
-
-void TextButtonBase::ClearEmbellishing() {
- has_shadow_ = false;
- has_text_halo_ = false;
-}
-
-void TextButtonBase::SetMultiLine(bool multi_line) {
- if (multi_line != multi_line_) {
- multi_line_ = multi_line;
- UpdateTextSize();
- PreferredSizeChanged();
- SchedulePaint();
- }
-}
-
-gfx::Size TextButtonBase::GetPreferredSize() {
- gfx::Insets insets = GetInsets();
-
- // Use the max size to set the button boundaries.
- gfx::Size prefsize(max_text_size_.width() + insets.width(),
- max_text_size_.height() + insets.height());
-
- if (max_width_ > 0)
- prefsize.set_width(std::min(max_width_, prefsize.width()));
-
- return prefsize;
-}
-
-int TextButtonBase::GetHeightForWidth(int w) {
- if (!multi_line_)
- return View::GetHeightForWidth(w);
-
- if (max_width_ > 0)
- w = std::min(max_width_, w);
-
- gfx::Size text_size;
- CalculateTextSize(&text_size, w);
- return text_size.height() + GetInsets().height();
-}
-
-void TextButtonBase::OnPaint(gfx::Canvas* canvas) {
- PaintButton(canvas, PB_NORMAL);
-}
-
-const ui::Animation* TextButtonBase::GetAnimation() const {
- return hover_animation_.get();
-}
-
-void TextButtonBase::UpdateColor() {
- color_ = View::IsEnabled() ? color_enabled_ : color_disabled_;
-}
-
-void TextButtonBase::UpdateTextSize() {
- CalculateTextSize(&text_size_, width());
- max_text_size_.SetSize(std::max(max_text_size_.width(), text_size_.width()),
- std::max(max_text_size_.height(),
- text_size_.height()));
- PreferredSizeChanged();
-}
-
-void TextButtonBase::CalculateTextSize(gfx::Size* text_size, int max_width) {
- int h = font_.GetHeight();
- int w = multi_line_ ? max_width : 0;
- int flags = ComputeCanvasStringFlags();
- if (!multi_line_)
- flags |= gfx::Canvas::NO_ELLIPSIS;
-
- gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags);
-
- // Add 2 extra pixels to width and height when text halo is used.
- if (has_text_halo_) {
- w += 2;
- h += 2;
- }
-
- text_size->SetSize(w, h);
-}
-
-int TextButtonBase::ComputeCanvasStringFlags() const {
- int flags = PrefixTypeToCanvasType(prefix_type_);
-
- if (multi_line_) {
- flags |= gfx::Canvas::MULTI_LINE;
-
- switch (alignment_) {
- case ALIGN_LEFT:
- flags |= gfx::Canvas::TEXT_ALIGN_LEFT;
- break;
- case ALIGN_RIGHT:
- flags |= gfx::Canvas::TEXT_ALIGN_RIGHT;
- break;
- case ALIGN_CENTER:
- flags |= gfx::Canvas::TEXT_ALIGN_CENTER;
- break;
- }
- }
-
- return flags;
-}
-
-void TextButtonBase::GetExtraParams(
- gfx::NativeTheme::ExtraParams* params) const {
- params->button.checked = false;
- params->button.indeterminate = false;
- params->button.is_default = false;
- params->button.has_border = false;
- params->button.classic_state = 0;
- params->button.background_color = kBackgroundColor;
-}
-
-gfx::Rect TextButtonBase::GetContentBounds(int extra_width) const {
- gfx::Insets insets = GetInsets();
- int available_width = width() - insets.width();
- int content_width = text_size_.width() + extra_width;
- int content_x = 0;
- switch(alignment_) {
- case ALIGN_LEFT:
- content_x = insets.left();
- break;
- case ALIGN_RIGHT:
- content_x = width() - insets.right() - content_width;
- if (content_x < insets.left())
- content_x = insets.left();
- break;
- case ALIGN_CENTER:
- content_x = insets.left() + std::max(0,
- (available_width - content_width) / 2);
- break;
- }
- content_width = std::min(content_width,
- width() - insets.right() - content_x);
- int available_height = height() - insets.height();
- int content_y = (available_height - text_size_.height()) / 2 + insets.top();
-
- gfx::Rect bounds(content_x, content_y, content_width, text_size_.height());
- return bounds;
-}
-
-gfx::Rect TextButtonBase::GetTextBounds() const {
- return GetContentBounds(0);
-}
-
-void TextButtonBase::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
- if (mode == PB_NORMAL) {
- OnPaintBackground(canvas);
- OnPaintBorder(canvas);
- OnPaintFocusBorder(canvas);
- }
-
- gfx::Rect text_bounds(GetTextBounds());
- if (text_bounds.width() > 0) {
- // Because the text button can (at times) draw multiple elements on the
- // canvas, we can not mirror the button by simply flipping the canvas as
- // doing this will mirror the text itself. Flipping the canvas will also
- // make the icons look wrong because icons are almost always represented as
- // direction-insensitive bitmaps and such bitmaps should never be flipped
- // horizontally.
- //
- // Due to the above, we must perform the flipping manually for RTL UIs.
- text_bounds.set_x(GetMirroredXForRect(text_bounds));
-
- SkColor text_color = (show_multiple_icon_states_ &&
- (state() == BS_HOT || state() == BS_PUSHED)) ? color_hover_ : color_;
-
- int draw_string_flags = gfx::CanvasSkia::DefaultCanvasTextAlignment() |
- ComputeCanvasStringFlags();
-
- if (mode == PB_FOR_DRAG) {
-#if defined(OS_WIN)
- // TODO(erg): Either port DrawStringWithHalo to linux or find an
- // alternative here.
- canvas->AsCanvasSkia()->DrawStringWithHalo(
- text_, font_, text_color, color_highlight_, text_bounds.x(),
- text_bounds.y(), text_bounds.width(), text_bounds.height(),
- draw_string_flags);
-#else
- canvas->DrawStringInt(text_,
- font_,
- text_color,
- text_bounds.x(),
- text_bounds.y(),
- text_bounds.width(),
- text_bounds.height(),
- draw_string_flags);
-#endif
- } else if (has_text_halo_) {
- canvas->AsCanvasSkia()->DrawStringWithHalo(
- text_, font_, text_color, text_halo_color_,
- text_bounds.x(), text_bounds.y(), text_bounds.width(),
- text_bounds.height(), draw_string_flags);
- } else if (has_shadow_) {
- SkColor shadow_color =
- GetWidget()->IsActive() ? active_text_shadow_color_ :
- inactive_text_shadow_color_;
- canvas->DrawStringInt(text_,
- font_,
- shadow_color,
- text_bounds.x() + shadow_offset_.x(),
- text_bounds.y() + shadow_offset_.y(),
- text_bounds.width(),
- text_bounds.height(),
- draw_string_flags);
- canvas->DrawStringInt(text_,
- font_,
- text_color,
- text_bounds.x(),
- text_bounds.y(),
- text_bounds.width(),
- text_bounds.height(),
- draw_string_flags);
- } else {
- canvas->DrawStringInt(text_,
- font_,
- text_color,
- text_bounds.x(),
- text_bounds.y(),
- text_bounds.width(),
- text_bounds.height(),
- draw_string_flags);
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// TextButtonBase, View overrides:
-
-gfx::Size TextButtonBase::GetMinimumSize() {
- return max_text_size_;
-}
-
-void TextButtonBase::OnEnabledChanged() {
- // We should always call UpdateColor() since the state of the button might be
- // changed by other functions like CustomButton::SetState().
- UpdateColor();
- CustomButton::OnEnabledChanged();
-}
-
-std::string TextButtonBase::GetClassName() const {
- return kViewClassName;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// TextButtonBase, NativeThemeDelegate overrides:
-
-gfx::Rect TextButtonBase::GetThemePaintRect() const {
- return GetLocalBounds();
-}
-
-gfx::NativeTheme::State TextButtonBase::GetThemeState(
- gfx::NativeTheme::ExtraParams* params) const {
- GetExtraParams(params);
- switch(state()) {
- case BS_DISABLED:
- return gfx::NativeTheme::kDisabled;
- case BS_NORMAL:
- return gfx::NativeTheme::kNormal;
- case BS_HOT:
- return gfx::NativeTheme::kHovered;
- case BS_PUSHED:
- return gfx::NativeTheme::kPressed;
- default:
- NOTREACHED() << "Unknown state: " << state();
- return gfx::NativeTheme::kNormal;
- }
-}
-
-const ui::Animation* TextButtonBase::GetThemeAnimation() const {
-#if defined(USE_AURA)
- return hover_animation_.get();
-#elif defined(OS_WIN)
- return gfx::NativeThemeWin::instance()->IsThemingActive()
- ? hover_animation_.get() : NULL;
-#else
- return hover_animation_.get();
-#endif
-}
-
-gfx::NativeTheme::State TextButtonBase::GetBackgroundThemeState(
- gfx::NativeTheme::ExtraParams* params) const {
- GetExtraParams(params);
- return gfx::NativeTheme::kNormal;
-}
-
-gfx::NativeTheme::State TextButtonBase::GetForegroundThemeState(
- gfx::NativeTheme::ExtraParams* params) const {
- GetExtraParams(params);
- return gfx::NativeTheme::kHovered;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// TextButton
-//
-////////////////////////////////////////////////////////////////////////////////
-
-TextButton::TextButton(ButtonListener* listener, const string16& text)
- : TextButtonBase(listener, text),
- icon_placement_(ICON_ON_LEFT),
- has_hover_icon_(false),
- has_pushed_icon_(false),
- icon_text_spacing_(kDefaultIconTextSpacing),
- ignore_minimum_size_(true) {
- set_border(new TextButtonBorder);
-}
-
-TextButton::~TextButton() {
-}
-
-void TextButton::SetIcon(const SkBitmap& icon) {
- icon_ = icon;
- SchedulePaint();
-}
-
-void TextButton::SetHoverIcon(const SkBitmap& icon) {
- icon_hover_ = icon;
- has_hover_icon_ = true;
- SchedulePaint();
-}
-
-void TextButton::SetPushedIcon(const SkBitmap& icon) {
- icon_pushed_ = icon;
- has_pushed_icon_ = true;
- SchedulePaint();
-}
-
-gfx::Size TextButton::GetPreferredSize() {
- gfx::Size prefsize(TextButtonBase::GetPreferredSize());
- prefsize.Enlarge(icon_.width(), 0);
- prefsize.set_height(std::max(prefsize.height(), icon_.height()));
-
- // Use the max size to set the button boundaries.
- if (icon_.width() > 0 && !text_.empty())
- prefsize.Enlarge(icon_text_spacing_, 0);
-
- if (max_width_ > 0)
- prefsize.set_width(std::min(max_width_, prefsize.width()));
-
-#if defined(OS_WIN)
- // Clamp the size returned to at least the minimum size.
- if (!ignore_minimum_size_) {
- gfx::PlatformFontWin* platform_font =
- static_cast<gfx::PlatformFontWin*>(font_.platform_font());
- prefsize.set_width(std::max(
- prefsize.width(),
- platform_font->horizontal_dlus_to_pixels(kMinWidthDLUs)));
- prefsize.set_height(std::max(
- prefsize.height(),
- platform_font->vertical_dlus_to_pixels(kMinHeightDLUs)));
- }
- // GTK returns a meaningful preferred size so that we don't need to adjust
- // the preferred size as we do on windows.
-#endif
-
- return prefsize;
-}
-
-void TextButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
- TextButtonBase::PaintButton(canvas, mode);
-
- const SkBitmap& icon = GetImageToPaint();
-
- if (icon.width() > 0) {
- gfx::Rect text_bounds = GetTextBounds();
- int icon_x;
- int spacing = text_.empty() ? 0 : icon_text_spacing_;
- if (icon_placement_ == ICON_ON_LEFT) {
- icon_x = text_bounds.x() - icon.width() - spacing;
- } else {
- icon_x = text_bounds.right() + spacing;
- }
-
- gfx::Insets insets = GetInsets();
- int available_height = height() - insets.height();
- int icon_y = (available_height - icon.height()) / 2 + insets.top();
-
- // Mirroring the icon position if necessary.
- gfx::Rect icon_bounds(icon_x, icon_y, icon.width(), icon.height());
- icon_bounds.set_x(GetMirroredXForRect(icon_bounds));
- canvas->DrawBitmapInt(icon, icon_bounds.x(), icon_bounds.y());
- }
-}
-
-void TextButton::set_ignore_minimum_size(bool ignore_minimum_size) {
- ignore_minimum_size_ = ignore_minimum_size;
-}
-
-std::string TextButton::GetClassName() const {
- return kViewClassName;
-}
-
-void TextButton::OnPaintFocusBorder(gfx::Canvas* canvas) {
- if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) {
- gfx::Rect rect(GetLocalBounds());
- rect.Inset(kFocusRectInset, kFocusRectInset);
- canvas->DrawFocusRect(rect);
- }
-}
-
-gfx::NativeTheme::Part TextButton::GetThemePart() const {
- return gfx::NativeTheme::kPushButton;
-}
-
-void TextButton::GetExtraParams(gfx::NativeTheme::ExtraParams* params) const {
- TextButtonBase::GetExtraParams(params);
- params->button.is_default = is_default_;
-}
-
-gfx::Rect TextButton::GetTextBounds() const {
- int extra_width = 0;
-
- const SkBitmap& icon = GetImageToPaint();
- if (icon.width() > 0)
- extra_width = icon.width() + (text_.empty() ? 0 : icon_text_spacing_);
-
- gfx::Rect bounds(GetContentBounds(extra_width));
-
- if (extra_width > 0) {
- // Make sure the icon is always fully visible.
- if (icon_placement_ == ICON_ON_LEFT) {
- bounds.Inset(extra_width, 0, 0, 0);
- } else {
- bounds.Inset(0, 0, extra_width, 0);
- }
- }
-
- return bounds;
-}
-
-const SkBitmap& TextButton::GetImageToPaint() const {
- if (show_multiple_icon_states_) {
- if (has_hover_icon_ && (state() == BS_HOT))
- return icon_hover_;
- if (has_pushed_icon_ && (state() == BS_PUSHED))
- return icon_pushed_;
- }
- return icon_;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// NativeTextButton
-//
-////////////////////////////////////////////////////////////////////////////////
-
-NativeTextButton::NativeTextButton(ButtonListener* listener)
- : TextButton(listener, string16()) {
- Init();
-}
-
-NativeTextButton::NativeTextButton(ButtonListener* listener,
- const string16& text)
- : TextButton(listener, text) {
- Init();
-}
-
-void NativeTextButton::Init() {
-#if defined(OS_WIN)
- // Windows will like to show its own colors.
- // Halos and such are ignored as they are always set by specific calls.
- color_enabled_ = skia::COLORREFToSkColor(GetSysColor(COLOR_BTNTEXT));
- color_disabled_ = skia::COLORREFToSkColor(GetSysColor(COLOR_GRAYTEXT));
- color_hover_ = color_ = color_enabled_;
-#endif
- set_border(new TextButtonNativeThemeBorder(this));
- set_ignore_minimum_size(false);
- set_alignment(ALIGN_CENTER);
- set_focusable(true);
-}
-
-gfx::Size NativeTextButton::GetMinimumSize() {
- return GetPreferredSize();
-}
-
-std::string NativeTextButton::GetClassName() const {
- return kViewClassName;
-}
-
-void NativeTextButton::OnPaintFocusBorder(gfx::Canvas* canvas) {
-#if defined(OS_WIN)
- if ((IsFocusable() || IsAccessibilityFocusableInRootView()) && HasFocus()) {
- gfx::Rect rect(GetLocalBounds());
- rect.Inset(kFocusRectInset, kFocusRectInset);
- canvas->DrawFocusRect(rect);
- }
-#else
- TextButton::OnPaintFocusBorder(canvas);
-#endif
-}
-
-void NativeTextButton::GetExtraParams(
- gfx::NativeTheme::ExtraParams* params) const {
- TextButton::GetExtraParams(params);
- params->button.has_border = true;
-}
-
-} // namespace views
diff --git a/views/controls/button/text_button.h b/views/controls/button/text_button.h
deleted file mode 100644
index 013fe74..0000000
--- a/views/controls/button/text_button.h
+++ /dev/null
@@ -1,431 +0,0 @@
-// Copyright (c) 2011 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.
-
-#ifndef VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_
-#define VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_
-#pragma once
-
-#include <string>
-
-#include "base/compiler_specific.h"
-#include "base/string16.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "third_party/skia/include/core/SkColor.h"
-#include "ui/gfx/font.h"
-#include "views/border.h"
-#include "views/controls/button/custom_button.h"
-#include "views/native_theme_delegate.h"
-
-namespace views {
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// TextButtonBorder
-//
-// A Border subclass that paints a TextButton's background layer -
-// basically the button frame in the hot/pushed states.
-//
-// Note that this type of button is not focusable by default and will not be
-// part of the focus chain. Call set_focusable(true) to make it part of the
-// focus chain.
-//
-////////////////////////////////////////////////////////////////////////////////
-class VIEWS_EXPORT TextButtonBorder : public Border {
- public:
- TextButtonBorder();
- virtual ~TextButtonBorder();
-
- // By default BS_NORMAL is drawn with no border. Call this to instead draw it
- // with the same border as the "hot" state.
- // TODO(pkasting): You should also call set_animate_on_state_change(false) on
- // the button in this case... we should fix this.
- void copy_normal_set_to_hot_set() { set_normal_set(hot_set_); }
-
- protected:
- struct BorderImageSet {
- SkBitmap* top_left;
- SkBitmap* top;
- SkBitmap* top_right;
- SkBitmap* left;
- SkBitmap* center;
- SkBitmap* right;
- SkBitmap* bottom_left;
- SkBitmap* bottom;
- SkBitmap* bottom_right;
- };
-
- void Paint(const View& view,
- gfx::Canvas* canvas,
- const BorderImageSet& set) const;
-
- void set_normal_set(const BorderImageSet& set) { normal_set_ = set; }
- void set_hot_set(const BorderImageSet& set) { hot_set_ = set; }
- void set_pushed_set(const BorderImageSet& set) { pushed_set_ = set; }
- void set_vertical_padding(int vertical_padding) {
- vertical_padding_ = vertical_padding;
- }
-
- private:
- // Border:
- virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE;
- virtual void GetInsets(gfx::Insets* insets) const OVERRIDE;
-
- BorderImageSet normal_set_;
- BorderImageSet hot_set_;
- BorderImageSet pushed_set_;
-
- int vertical_padding_;
-
- DISALLOW_COPY_AND_ASSIGN(TextButtonBorder);
-};
-
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// TextButtonNativeThemeBorder
-//
-// A Border subclass that paints a TextButton's background layer using the
-// platform's native theme look. This handles normal/disabled/hot/pressed
-// states, with possible animation between states.
-//
-////////////////////////////////////////////////////////////////////////////////
-class VIEWS_EXPORT TextButtonNativeThemeBorder : public Border {
- public:
- TextButtonNativeThemeBorder(NativeThemeDelegate* delegate);
- virtual ~TextButtonNativeThemeBorder();
-
- // Implementation of Border:
- virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE;
- virtual void GetInsets(gfx::Insets* insets) const OVERRIDE;
-
- private:
- // The delegate the controls the appearance of this border.
- NativeThemeDelegate* delegate_;
-
- DISALLOW_COPY_AND_ASSIGN(TextButtonNativeThemeBorder);
-};
-
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// TextButtonBase
-//
-// A base ckass for different types of buttons, like push buttons, radio
-// buttons, and checkboxes, that do not depende on native components for
-// look and feel. TextButton reserves space for the largest string
-// passed to SetText. To reset the cached max size invoke ClearMaxTextSize.
-//
-////////////////////////////////////////////////////////////////////////////////
-class VIEWS_EXPORT TextButtonBase : public CustomButton,
- public NativeThemeDelegate {
- public:
- // The menu button's class name.
- static const char kViewClassName[];
-
- // Enumeration of how the prefix ('&') character is processed. The default
- // is |PREFIX_NONE|.
- enum PrefixType {
- // No special processing is done.
- PREFIX_NONE,
-
- // The character following the prefix character is not rendered specially.
- PREFIX_HIDE,
-
- // The character following the prefix character is underlined.
- PREFIX_SHOW
- };
-
- virtual ~TextButtonBase();
-
- // Call SetText once per string in your set of possible values at button
- // creation time, so that it can contain the largest of them and avoid
- // resizing the button when the text changes.
- virtual void SetText(const string16& text);
- const string16& text() const { return text_; }
-
- enum TextAlignment {
- ALIGN_LEFT,
- ALIGN_CENTER,
- ALIGN_RIGHT
- };
-
- void set_alignment(TextAlignment alignment) { alignment_ = alignment; }
-
- void set_prefix_type(PrefixType type) { prefix_type_ = type; }
-
- const ui::Animation* GetAnimation() const;
-
- void SetIsDefault(bool is_default);
- bool is_default() const { return is_default_; }
-
- // Set whether the button text can wrap on multiple lines.
- // Default is false.
- void SetMultiLine(bool multi_line);
-
- // Return whether the button text can wrap on multiple lines.
- bool multi_line() const { return multi_line_; }
-
- // TextButton remembers the maximum display size of the text passed to
- // SetText. This method resets the cached maximum display size to the
- // current size.
- void ClearMaxTextSize();
-
- void set_max_width(int max_width) { max_width_ = max_width; }
- void SetFont(const gfx::Font& font);
- // Return the font used by this button.
- gfx::Font font() const { return font_; }
-
- void SetEnabledColor(SkColor color);
- void SetDisabledColor(SkColor color);
- void SetHighlightColor(SkColor color);
- void SetHoverColor(SkColor color);
- void SetTextHaloColor(SkColor color);
- // The shadow color used is determined by whether the widget is active or
- // inactive. Both possible colors are set in this method, and the
- // appropriate one is chosen during Paint.
- void SetTextShadowColors(SkColor active_color, SkColor inactive_color);
- void SetTextShadowOffset(int x, int y);
-
- // Sets whether or not to show the hot and pushed states for the button icon
- // (if present) in addition to the normal state. Defaults to true.
- bool show_multiple_icon_states() const { return show_multiple_icon_states_; }
- void SetShowMultipleIconStates(bool show_multiple_icon_states);
-
- // Clears halo and shadow settings.
- void ClearEmbellishing();
-
- // Paint the button into the specified canvas. If |mode| is |PB_FOR_DRAG|, the
- // function paints a drag image representation into the canvas.
- enum PaintButtonMode { PB_NORMAL, PB_FOR_DRAG };
- virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode);
-
- // Overridden from View:
- virtual gfx::Size GetPreferredSize() OVERRIDE;
- virtual gfx::Size GetMinimumSize() OVERRIDE;
- virtual int GetHeightForWidth(int w) OVERRIDE;
- virtual void OnEnabledChanged() OVERRIDE;
- virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
-
- // Text colors.
- static const SkColor kEnabledColor;
- static const SkColor kHighlightColor;
- static const SkColor kDisabledColor;
- static const SkColor kHoverColor;
-
- // Returns views/TextButton.
- virtual std::string GetClassName() const OVERRIDE;
-
- protected:
- TextButtonBase(ButtonListener* listener, const string16& text);
-
- // Called when enabled or disabled state changes, or the colors for those
- // states change.
- virtual void UpdateColor();
-
- // Updates text_size_ and max_text_size_ from the current text/font. This is
- // invoked when the font or text changes.
- void UpdateTextSize();
-
- // Calculate the size of the text size without setting any of the members.
- void CalculateTextSize(gfx::Size* text_size, int max_width);
-
- // Overridden from NativeThemeDelegate:
- virtual gfx::Rect GetThemePaintRect() const OVERRIDE;
- virtual gfx::NativeTheme::State GetThemeState(
- gfx::NativeTheme::ExtraParams* params) const OVERRIDE;
- virtual const ui::Animation* GetThemeAnimation() const OVERRIDE;
- virtual gfx::NativeTheme::State GetBackgroundThemeState(
- gfx::NativeTheme::ExtraParams* params) const OVERRIDE;
- virtual gfx::NativeTheme::State GetForegroundThemeState(
- gfx::NativeTheme::ExtraParams* params) const OVERRIDE;
-
- virtual void GetExtraParams(gfx::NativeTheme::ExtraParams* params) const;
-
- virtual gfx::Rect GetTextBounds() const;
-
- int ComputeCanvasStringFlags() const;
-
- // Calculate the bounds of the content of this button, including any extra
- // width needed on top of the text width.
- gfx::Rect GetContentBounds(int extra_width) const;
-
- // The text string that is displayed in the button.
- string16 text_;
-
- // The size of the text string.
- gfx::Size text_size_;
-
- // Track the size of the largest text string seen so far, so that
- // changing text_ will not resize the button boundary.
- gfx::Size max_text_size_;
-
- // The alignment of the text string within the button.
- TextAlignment alignment_;
-
- // The font used to paint the text.
- gfx::Font font_;
-
- // Text color.
- SkColor color_;
-
- // State colors.
- SkColor color_enabled_;
- SkColor color_disabled_;
- SkColor color_highlight_;
- SkColor color_hover_;
-
- // An optional halo around text.
- SkColor text_halo_color_;
- bool has_text_halo_;
-
- // Optional shadow text colors for active and inactive widget states.
- SkColor active_text_shadow_color_;
- SkColor inactive_text_shadow_color_;
- bool has_shadow_;
- // Space between text and shadow. Defaults to (1,1).
- gfx::Point shadow_offset_;
-
- // The width of the button will never be larger than this value. A value <= 0
- // indicates the width is not constrained.
- int max_width_;
-
- // Whether or not to show the hot and pushed icon states.
- bool show_multiple_icon_states_;
-
- // Whether or not the button appears and behaves as the default button in its
- // current context.
- bool is_default_;
-
- // Whether the text button should handle its text string as multi-line.
- bool multi_line_;
-
- PrefixType prefix_type_;
-
- DISALLOW_COPY_AND_ASSIGN(TextButtonBase);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// TextButton
-//
-// A button which displays text and/or and icon that can be changed in
-// response to actions. TextButton reserves space for the largest string
-// passed to SetText. To reset the cached max size invoke ClearMaxTextSize.
-//
-////////////////////////////////////////////////////////////////////////////////
-class VIEWS_EXPORT TextButton : public TextButtonBase {
- public:
- // The button's class name.
- static const char kViewClassName[];
-
- TextButton(ButtonListener* listener, const string16& text);
- virtual ~TextButton();
-
- void set_icon_text_spacing(int icon_text_spacing) {
- icon_text_spacing_ = icon_text_spacing;
- }
-
- // Sets the icon.
- virtual void SetIcon(const SkBitmap& icon);
- virtual void SetHoverIcon(const SkBitmap& icon);
- virtual void SetPushedIcon(const SkBitmap& icon);
-
- bool HasIcon() const { return !icon_.empty(); }
-
- // Meanings are reversed for right-to-left layouts.
- enum IconPlacement {
- ICON_ON_LEFT,
- ICON_ON_RIGHT
- };
-
- IconPlacement icon_placement() { return icon_placement_; }
- void set_icon_placement(IconPlacement icon_placement) {
- icon_placement_ = icon_placement;
- }
-
- void set_ignore_minimum_size(bool ignore_minimum_size);
-
- // Overridden from View:
- virtual gfx::Size GetPreferredSize() OVERRIDE;
- virtual std::string GetClassName() const OVERRIDE;
- virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
-
- // Overridden from TextButtonBase:
- virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) OVERRIDE;
-
- protected:
- SkBitmap icon() const { return icon_; }
-
- virtual const SkBitmap& GetImageToPaint() const;
-
- // Overridden from NativeThemeDelegate:
- virtual gfx::NativeTheme::Part GetThemePart() const OVERRIDE;
-
- // Overridden from TextButtonBase:
- virtual void GetExtraParams(
- gfx::NativeTheme::ExtraParams* params) const OVERRIDE;
- virtual gfx::Rect GetTextBounds() const OVERRIDE;
-
- private:
- // The position of the icon.
- IconPlacement icon_placement_;
-
- // An icon displayed with the text.
- SkBitmap icon_;
-
- // An optional different version of the icon for hover state.
- SkBitmap icon_hover_;
- bool has_hover_icon_;
-
- // An optional different version of the icon for pushed state.
- SkBitmap icon_pushed_;
- bool has_pushed_icon_;
-
- // Space between icon and text.
- int icon_text_spacing_;
-
- // True if the button should ignore the minimum size for the platform. Default
- // is true. Set to false to prevent narrower buttons.
- bool ignore_minimum_size_;
-
- DISALLOW_COPY_AND_ASSIGN(TextButton);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// NativeTextButton
-//
-// A TextButton that uses the NativeTheme border and sets some properties,
-// like ignore-minimize-size and text alignment minimum size.
-//
-////////////////////////////////////////////////////////////////////////////////
-class VIEWS_EXPORT NativeTextButton : public TextButton {
- public:
- // The button's class name.
- static const char kViewClassName[];
-
- NativeTextButton(ButtonListener* listener);
- NativeTextButton(ButtonListener* listener, const string16& text);
-
- // Overridden from TextButton:
- virtual gfx::Size GetMinimumSize() OVERRIDE;
-
- virtual std::string GetClassName() const OVERRIDE;
-
- private:
- void Init();
-
- // Overridden from View:
- virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
-
- // Overridden from TextButton:
- virtual void GetExtraParams(
- gfx::NativeTheme::ExtraParams* params) const OVERRIDE;
-
- DISALLOW_COPY_AND_ASSIGN(NativeTextButton);
-};
-
-} // namespace views
-
-#endif // VIEWS_CONTROLS_BUTTON_TEXT_BUTTON_H_