summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-16 20:16:43 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-16 20:16:43 +0000
commit72279de2022a9c5e862963baf000b54ec559d8ed (patch)
tree14fbea01a08a9c7276ecb1981b95988ae2de0143 /views
parent9e7b3f08a3e65b88fbb91045450b55582dd745b6 (diff)
downloadchromium_src-72279de2022a9c5e862963baf000b54ec559d8ed.zip
chromium_src-72279de2022a9c5e862963baf000b54ec559d8ed.tar.gz
chromium_src-72279de2022a9c5e862963baf000b54ec559d8ed.tar.bz2
Reorder some views::View overrides & other functions.
Follow base class ordering and access specifiers. Add OVERRIDE keyword where applicable. Define BaseTab::set_animation_container out of line, update includes. Limit RenderWidgetHostViewViews::OnTouchEvent to TOUCH_UI. Make RenderWidgetHostViewViews::GetCursorForPoint a virtual override. Review URL: http://codereview.chromium.org/6673070 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78416 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/button/button_dropdown.cc52
-rw-r--r--views/controls/button/button_dropdown.h17
-rw-r--r--views/controls/button/checkbox.cc100
-rw-r--r--views/controls/button/checkbox.h35
-rw-r--r--views/controls/button/custom_button.cc178
-rw-r--r--views/controls/button/custom_button.h55
-rw-r--r--views/controls/button/menu_button.cc126
-rw-r--r--views/controls/button/menu_button.h25
-rw-r--r--views/controls/label.cc208
-rw-r--r--views/controls/label.h73
-rw-r--r--views/controls/menu/menu_host_root_view.cc12
-rw-r--r--views/controls/menu/menu_host_root_view.h7
-rw-r--r--views/controls/scrollbar/bitmap_scroll_bar.cc41
-rw-r--r--views/controls/scrollbar/bitmap_scroll_bar.h7
-rw-r--r--views/widget/root_view.cc56
-rw-r--r--views/widget/root_view.h12
16 files changed, 487 insertions, 517 deletions
diff --git a/views/controls/button/button_dropdown.cc b/views/controls/button/button_dropdown.cc
index cdd93c3..c2da598 100644
--- a/views/controls/button/button_dropdown.cc
+++ b/views/controls/button/button_dropdown.cc
@@ -57,6 +57,22 @@ bool ButtonDropDown::OnMousePressed(const MouseEvent& event) {
return ImageButton::OnMousePressed(event);
}
+bool ButtonDropDown::OnMouseDragged(const MouseEvent& event) {
+ bool result = ImageButton::OnMouseDragged(event);
+
+ if (!show_menu_factory_.empty()) {
+ // 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_.RevokeAll();
+ ShowDropDownMenu(GetWidget()->GetNativeView());
+ }
+ }
+
+ return result;
+}
+
void ButtonDropDown::OnMouseReleased(const MouseEvent& event, bool canceled) {
// Showing the drop down results in a MouseReleased with a canceled drag, we
// need to ignore it.
@@ -77,22 +93,6 @@ void ButtonDropDown::OnMouseReleased(const MouseEvent& event, bool canceled) {
}
}
-bool ButtonDropDown::OnMouseDragged(const MouseEvent& event) {
- bool result = ImageButton::OnMouseDragged(event);
-
- if (!show_menu_factory_.empty()) {
- // 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_.RevokeAll();
- ShowDropDownMenu(GetWidget()->GetNativeView());
- }
- }
-
- return result;
-}
-
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
@@ -101,12 +101,6 @@ void ButtonDropDown::OnMouseExited(const MouseEvent& event) {
SetState(BS_NORMAL);
}
-////////////////////////////////////////////////////////////////////////////////
-//
-// ButtonDropDown - Menu functions
-//
-////////////////////////////////////////////////////////////////////////////////
-
void ButtonDropDown::ShowContextMenu(const gfx::Point& p,
bool is_mouse_gesture) {
show_menu_factory_.RevokeAll();
@@ -114,6 +108,13 @@ void ButtonDropDown::ShowContextMenu(const gfx::Point& p,
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.
@@ -165,11 +166,4 @@ void ButtonDropDown::ShowDropDownMenu(gfx::NativeView window) {
//
////////////////////////////////////////////////////////////////////////////////
-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;
-}
-
} // namespace views
diff --git a/views/controls/button/button_dropdown.h b/views/controls/button/button_dropdown.h
index fe558e1..0a62584 100644
--- a/views/controls/button/button_dropdown.h
+++ b/views/controls/button/button_dropdown.h
@@ -25,28 +25,25 @@ class ButtonDropDown : public ImageButton {
ButtonDropDown(ButtonListener* listener, ui::MenuModel* model);
virtual ~ButtonDropDown();
- // Accessibility accessors, overridden from View.
- virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
-
- private:
- // Overridden from CustomButton
+ // Overridden from views::View
virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE;
virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE;
+ virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE;
virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
-
- // Overridden from View. Used to display the right-click menu, as triggered
- // by the keyboard, for instance. Using the member function ShowDropDownMenu
- // for the actual display.
+ // 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);
diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc
index 45aea1c..693e282 100644
--- a/views/controls/button/checkbox.cc
+++ b/views/controls/button/checkbox.cc
@@ -34,6 +34,11 @@ Checkbox::Checkbox(const std::wstring& label)
Checkbox::~Checkbox() {
}
+// static
+int Checkbox::GetTextIndent() {
+ return NativeButtonWrapper::GetFixedWidth() + kCheckboxLabelSpacing;
+}
+
void Checkbox::SetMultiLine(bool multiline) {
label_->SetMultiLine(multiline);
PreferredSizeChanged();
@@ -47,11 +52,6 @@ void Checkbox::SetChecked(bool checked) {
native_wrapper_->UpdateChecked();
}
-// static
-int Checkbox::GetTextIndent() {
- return NativeButtonWrapper::GetFixedWidth() + kCheckboxLabelSpacing;
-}
-
////////////////////////////////////////////////////////////////////////////////
// Checkbox, View overrides:
@@ -87,6 +87,12 @@ int Checkbox::GetHeightForWidth(int w) {
return label_->GetHeightForWidth(std::max(prefsize.height(), w - width));
}
+void Checkbox::SetEnabled(bool enabled) {
+ NativeButton::SetEnabled(enabled);
+ if (label_)
+ label_->SetEnabled(enabled);
+}
+
void Checkbox::Layout() {
if (!native_wrapper_)
return;
@@ -112,26 +118,8 @@ void Checkbox::Layout() {
native_wrapper_->GetView()->Layout();
}
-void Checkbox::SetEnabled(bool enabled) {
- NativeButton::SetEnabled(enabled);
- if (label_)
- label_->SetEnabled(enabled);
-}
-
-void Checkbox::OnPaintFocusBorder(gfx::Canvas* canvas) {
- // Our focus border is rendered by the label, so we don't do anything here.
-}
-
-void Checkbox::OnMouseEntered(const MouseEvent& event) {
- native_wrapper_->SetPushed(HitTestLabel(event));
-}
-
-void Checkbox::OnMouseMoved(const MouseEvent& event) {
- native_wrapper_->SetPushed(HitTestLabel(event));
-}
-
-void Checkbox::OnMouseExited(const MouseEvent& event) {
- native_wrapper_->SetPushed(false);
+std::string Checkbox::GetClassName() const {
+ return kViewClassName;
}
bool Checkbox::OnMousePressed(const MouseEvent& event) {
@@ -139,6 +127,10 @@ bool Checkbox::OnMousePressed(const MouseEvent& event) {
return true;
}
+bool Checkbox::OnMouseDragged(const MouseEvent& event) {
+ return false;
+}
+
void Checkbox::OnMouseReleased(const MouseEvent& event, bool canceled) {
native_wrapper_->SetPushed(false);
if (!canceled && HitTestLabel(event)) {
@@ -147,16 +139,16 @@ void Checkbox::OnMouseReleased(const MouseEvent& event, bool canceled) {
}
}
-bool Checkbox::OnMouseDragged(const MouseEvent& event) {
- return false;
+void Checkbox::OnMouseMoved(const MouseEvent& event) {
+ native_wrapper_->SetPushed(HitTestLabel(event));
}
-void Checkbox::OnFocus() {
- label_->set_paint_as_focused(true);
+void Checkbox::OnMouseEntered(const MouseEvent& event) {
+ native_wrapper_->SetPushed(HitTestLabel(event));
}
-void Checkbox::OnBlur() {
- label_->set_paint_as_focused(false);
+void Checkbox::OnMouseExited(const MouseEvent& event) {
+ native_wrapper_->SetPushed(false);
}
void Checkbox::GetAccessibleState(ui::AccessibleViewState* state) {
@@ -165,25 +157,9 @@ void Checkbox::GetAccessibleState(ui::AccessibleViewState* state) {
state->state = checked() ? ui::AccessibilityTypes::STATE_CHECKED : 0;
}
-std::string Checkbox::GetClassName() const {
- return kViewClassName;
-}
-
////////////////////////////////////////////////////////////////////////////////
// Checkbox, NativeButton overrides:
-NativeButtonWrapper* Checkbox::CreateWrapper() {
- NativeButtonWrapper* native_wrapper =
- NativeButtonWrapper::CreateCheckboxWrapper(this);
- native_wrapper->UpdateLabel();
- native_wrapper->UpdateChecked();
- return native_wrapper;
-}
-
-void Checkbox::InitBorder() {
- // No border, so we do nothing.
-}
-
void Checkbox::SetLabel(const std::wstring& label) {
NativeButton::SetLabel(label);
if (!native_wrapper_->UsesNativeLabel())
@@ -200,6 +176,36 @@ bool Checkbox::HitTestLabel(const MouseEvent& event) {
}
////////////////////////////////////////////////////////////////////////////////
+// Checkbox, View overrides, protected:
+
+void Checkbox::OnPaintFocusBorder(gfx::Canvas* canvas) {
+ // Our focus border is rendered by the label, so we don't do anything here.
+}
+void Checkbox::OnFocus() {
+ label_->set_paint_as_focused(true);
+}
+
+void Checkbox::OnBlur() {
+ label_->set_paint_as_focused(false);
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// Checkbox, NativeButton overrides, protected:
+
+NativeButtonWrapper* Checkbox::CreateWrapper() {
+ NativeButtonWrapper* native_wrapper =
+ NativeButtonWrapper::CreateCheckboxWrapper(this);
+ native_wrapper->UpdateLabel();
+ native_wrapper->UpdateChecked();
+ return native_wrapper;
+}
+
+void Checkbox::InitBorder() {
+ // No border, so we do nothing.
+}
+
+////////////////////////////////////////////////////////////////////////////////
// Checkbox, private:
void Checkbox::Init(const std::wstring& label_text) {
diff --git a/views/controls/button/checkbox.h b/views/controls/button/checkbox.h
index 75660b4..19491e9 100644
--- a/views/controls/button/checkbox.h
+++ b/views/controls/button/checkbox.h
@@ -24,6 +24,9 @@ class Checkbox : public NativeButton {
explicit Checkbox(const std::wstring& label);
virtual ~Checkbox();
+ // Returns the indentation of the text from the left edge of the view.
+ static int GetTextIndent();
+
// 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; }
@@ -38,41 +41,37 @@ class Checkbox : public NativeButton {
virtual void SetChecked(bool checked);
bool checked() const { return checked_; }
- // Returns the indentation of the text from the left edge of the view.
- static int GetTextIndent();
-
// Overridden from View:
virtual gfx::Size GetPreferredSize() OVERRIDE;
virtual int GetHeightForWidth(int w) OVERRIDE;
- virtual void Layout() OVERRIDE;
virtual void SetEnabled(bool enabled) OVERRIDE;
- virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
- virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
+ virtual void Layout() OVERRIDE;
+ virtual std::string GetClassName() const OVERRIDE;
virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE;
virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE;
- virtual void OnFocus() OVERRIDE;
- virtual void OnBlur() OVERRIDE;
-
- // Accessibility accessors, overridden from View.
+ virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE;
+ virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE;
+ virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE;
+ virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
// Overridden from NativeButton:
virtual void SetLabel(const std::wstring& label) OVERRIDE;
protected:
- virtual std::string GetClassName() const OVERRIDE;
+ // Returns true if the event (in Checkbox coordinates) is within the bounds of
+ // the label.
+ bool HitTestLabel(const MouseEvent& event);
+
+ // Overridden from View:
+ virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
+ virtual void OnFocus() OVERRIDE;
+ virtual void OnBlur() OVERRIDE;
// Overridden from NativeButton:
virtual NativeButtonWrapper* CreateWrapper() OVERRIDE;
virtual void InitBorder() OVERRIDE;
- // Returns true if the event (in Checkbox coordinates) is within the bounds of
- // the label.
- bool HitTestLabel(const MouseEvent& event);
-
private:
// Called from the constructor to create and configure the checkbox label.
void Init(const std::wstring& label_text);
diff --git a/views/controls/button/custom_button.cc b/views/controls/button/custom_button.cc
index 2e7b4cdd..887e0b4 100644
--- a/views/controls/button/custom_button.cc
+++ b/views/controls/button/custom_button.cc
@@ -56,28 +56,34 @@ 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(Screen::GetCursorScreenPoint());
+ ConvertPointToView(NULL, this, &cursor_pos);
+ return HitTest(cursor_pos);
+}
+
////////////////////////////////////////////////////////////////////////////////
// CustomButton, View overrides:
-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;
+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::SetEnabled(bool enabled) {
if (enabled ? (state_ != BS_DISABLED) : (state_ == BS_DISABLED))
return;
@@ -92,57 +98,10 @@ bool CustomButton::IsEnabled() const {
return state_ != BS_DISABLED;
}
-bool CustomButton::IsFocusable() const {
- return (state_ != BS_DISABLED) && View::IsFocusable();
-}
-
-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(Screen::GetCursorScreenPoint());
- ConvertPointToView(NULL, this, &cursor_pos);
- return HitTest(cursor_pos);
-}
-
std::string CustomButton::GetClassName() const {
return kViewClassName;
}
-////////////////////////////////////////////////////////////////////////////////
-// 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);
-}
-
-bool CustomButton::IsTriggerableEvent(const MouseEvent& event) {
- return (triggerable_event_flags_ & event.flags()) != 0;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// CustomButton, View overrides (protected):
-
-bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) {
- if (!enabled_)
- return false;
-
- SetState(BS_NORMAL);
- KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.GetKeyCode(),
- accelerator.modifiers());
- NotifyClick(key_event);
- return true;
-}
-
bool CustomButton::OnMousePressed(const MouseEvent& event) {
if (state_ != BS_DISABLED) {
if (ShouldEnterPushedState(event) && HitTest(event.location()))
@@ -186,17 +145,17 @@ void CustomButton::OnMouseEntered(const MouseEvent& event) {
SetState(BS_HOT);
}
-void CustomButton::OnMouseMoved(const MouseEvent& event) {
- if (state_ != BS_DISABLED)
- SetState(HitTest(event.location()) ? BS_HOT : BS_NORMAL);
-}
-
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;
@@ -224,8 +183,15 @@ bool CustomButton::OnKeyReleased(const KeyEvent& event) {
return true;
}
-void CustomButton::OnDragDone() {
+bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) {
+ if (!enabled_)
+ return false;
+
SetState(BS_NORMAL);
+ KeyEvent key_event(ui::ET_KEY_RELEASED, accelerator.GetKeyCode(),
+ accelerator.modifiers());
+ NotifyClick(key_event);
+ return true;
}
void CustomButton::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) {
@@ -239,31 +205,29 @@ void CustomButton::ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) {
View::ShowContextMenu(p, is_mouse_gesture);
}
-void CustomButton::ViewHierarchyChanged(bool is_add, View *parent,
- View *child) {
- if (!is_add && state_ != BS_DISABLED)
- SetState(BS_NORMAL);
+void CustomButton::OnDragDone() {
+ SetState(BS_NORMAL);
}
-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);
+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;
}
}
-bool CustomButton::IsHotTracked() const {
- return state_ == BS_HOT;
-}
-
-void CustomButton::OnBlur() {
- if (IsHotTracked())
- SetState(BS_NORMAL);
-}
-
////////////////////////////////////////////////////////////////////////////////
// CustomButton, ui::AnimationDelegate implementation:
@@ -271,8 +235,44 @@ 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);
+}
+
+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
index 3f6f22a..b9e1d31 100644
--- a/views/controls/button/custom_button.h
+++ b/views/controls/button/custom_button.h
@@ -47,19 +47,10 @@ class CustomButton : public Button,
// Set how long the hover animation will last for.
void SetAnimationDuration(int duration);
- // Overridden from View:
- virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
- virtual void SetEnabled(bool enabled) OVERRIDE;
- virtual bool IsEnabled() const OVERRIDE;
- virtual bool IsFocusable() const OVERRIDE;
-
void set_triggerable_event_flags(int triggerable_event_flags) {
triggerable_event_flags_ = triggerable_event_flags;
}
-
- int triggerable_event_flags() const {
- return 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.
@@ -78,45 +69,49 @@ class CustomButton : public Button,
// when it's disabled.
bool IsMouseHovered() const;
- // Returns views/CustomButton.
- virtual std::string GetClassName() const;
-
- protected:
- // Construct the Button with a Listener. See comment for Button's ctor.
- explicit CustomButton(ButtonListener* listener);
-
- // 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);
-
// Overridden from View:
- virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE;
+ virtual void SetHotTracked(bool flag) OVERRIDE;
+ virtual bool IsHotTracked() const OVERRIDE;
+ virtual void SetEnabled(bool enabled) 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, bool canceled) OVERRIDE;
virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseMoved(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 void OnDragDone() OVERRIDE;
+ virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE;
virtual void ShowContextMenu(const gfx::Point& p,
bool is_mouse_gesture) OVERRIDE;
- virtual void ViewHierarchyChanged(bool is_add,
- View* parent,
- View* child) OVERRIDE;
- virtual void SetHotTracked(bool flag) OVERRIDE;
- virtual bool IsHotTracked() const OVERRIDE;
- virtual void OnBlur() 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);
+
+ // 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_;
diff --git a/views/controls/button/menu_button.cc b/views/controls/button/menu_button.cc
index 822ca39..3ada964 100644
--- a/views/controls/button/menu_button.cc
+++ b/views/controls/button/menu_button.cc
@@ -72,53 +72,6 @@ MenuButton::~MenuButton() {
//
////////////////////////////////////////////////////////////////////////////////
-gfx::Size MenuButton::GetPreferredSize() {
- gfx::Size prefsize = TextButton::GetPreferredSize();
- if (show_menu_marker_) {
- prefsize.Enlarge(menu_marker_->width() + kMenuMarkerPaddingLeft +
- kMenuMarkerPaddingRight,
- 0);
- }
- return prefsize;
-}
-
-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
-//
-////////////////////////////////////////////////////////////////////////////////
-
-int MenuButton::GetMaximumScreenXCoordinate() {
- if (!GetWidget()) {
- NOTREACHED();
- return 0;
- }
-
- gfx::Rect monitor_bounds =
- Screen::GetMonitorWorkAreaNearestWindow(GetWidget()->GetNativeView());
- return monitor_bounds.right() - 1;
-}
-
bool MenuButton::Activate() {
SetState(BS_PUSHED);
// We need to synchronously paint here because subsequently we enter a
@@ -188,6 +141,46 @@ bool MenuButton::Activate() {
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) {
@@ -219,6 +212,17 @@ void MenuButton::OnMouseReleased(const MouseEvent& event, bool canceled) {
}
}
+// 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:
@@ -243,23 +247,6 @@ bool MenuButton::OnKeyReleased(const KeyEvent& event) {
return false;
}
-// 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);
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// MenuButton - accessibility
-//
-////////////////////////////////////////////////////////////////////////////////
-
void MenuButton::GetAccessibleState(ui::AccessibleViewState* state) {
CustomButton::GetAccessibleState(state);
state->role = ui::AccessibilityTypes::ROLE_BUTTONMENU;
@@ -267,8 +254,15 @@ void MenuButton::GetAccessibleState(ui::AccessibleViewState* state) {
state->state = ui::AccessibilityTypes::STATE_HASPOPUP;
}
-std::string MenuButton::GetClassName() const {
- return kViewClassName;
+int MenuButton::GetMaximumScreenXCoordinate() {
+ if (!GetWidget()) {
+ NOTREACHED();
+ return 0;
+ }
+
+ gfx::Rect monitor_bounds =
+ Screen::GetMonitorWorkAreaNearestWindow(GetWidget()->GetNativeView());
+ return monitor_bounds.right() - 1;
}
} // namespace views
diff --git a/views/controls/button/menu_button.h b/views/controls/button/menu_button.h
index d9622e4..b564b1c 100644
--- a/views/controls/button/menu_button.h
+++ b/views/controls/button/menu_button.h
@@ -42,36 +42,25 @@ class MenuButton : public TextButton {
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 to take into account the potential use of a drop marker.
- virtual gfx::Size GetPreferredSize() OVERRIDE;
+ // Overridden from TextButton for the potential use of a drop marker.
virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) OVERRIDE;
- // These methods are overriden to implement a simple push button
- // behavior.
+ // 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, bool canceled) OVERRIDE;
virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE;
virtual bool OnKeyReleased(const KeyEvent& event) OVERRIDE;
-
- // Accessibility accessors, overridden from View.
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
- // Returns views/MenuButton.
- virtual std::string GetClassName() const OVERRIDE;
-
- // Accessors for menu_offset_.
- const gfx::Point& menu_offset() const {
- return menu_offset_;
- }
-
- void set_menu_offset(int x, int y) {
- menu_offset_.SetPoint(x, y);
- }
-
protected:
// True if the menu is currently visible.
bool menu_visible_;
diff --git a/views/controls/label.cc b/views/controls/label.cc
index c422ad0..80454c3 100644
--- a/views/controls/label.cc
+++ b/views/controls/label.cc
@@ -44,58 +44,6 @@ Label::Label(const std::wstring& text, const gfx::Font& font) {
Label::~Label() {
}
-gfx::Size Label::GetPreferredSize() {
- // Return a size of (0, 0) if the label is not visible and if the
- // collapse_when_hidden_ flag is set.
- // TODO(munjal): This logic probably belongs to the View class. But for now,
- // put it here since putting it in View class means all inheriting classes
- // need ot respect the collapse_when_hidden_ flag.
- if (!IsVisible() && collapse_when_hidden_)
- return gfx::Size();
-
- gfx::Size prefsize(GetTextSize());
- gfx::Insets insets = GetInsets();
- prefsize.Enlarge(insets.width(), insets.height());
- return prefsize;
-}
-
-int Label::GetBaseline() {
- return GetInsets().top() + font_.GetBaseline();
-}
-
-int Label::GetHeightForWidth(int w) {
- if (!is_multi_line_)
- return View::GetHeightForWidth(w);
-
- w = std::max(0, w - GetInsets().width());
- int h = font_.GetHeight();
- gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h,
- ComputeMultiLineFlags());
- return h + GetInsets().height();
-}
-
-std::string Label::GetClassName() const {
- return kViewClassName;
-}
-
-void Label::OnPaint(gfx::Canvas* canvas) {
- OnPaintBackground(canvas);
-
- std::wstring paint_text;
- gfx::Rect text_bounds;
- int flags = 0;
- CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
- PaintText(canvas, paint_text, text_bounds, flags);
-}
-
-void Label::OnPaintBackground(gfx::Canvas* canvas) {
- const Background* bg = contains_mouse_ ? GetMouseOverBackground() : NULL;
- if (!bg)
- bg = background();
- if (bg)
- bg->Paint(canvas, this);
-}
-
void Label::SetFont(const gfx::Font& font) {
font_ = font;
text_size_valid_ = false;
@@ -182,36 +130,6 @@ void Label::SetTooltipText(const std::wstring& tooltip_text) {
tooltip_text_ = WideToUTF16Hack(tooltip_text);
}
-bool Label::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) {
- DCHECK(tooltip);
-
- // If a tooltip has been explicitly set, use it.
- if (!tooltip_text_.empty()) {
- tooltip->assign(UTF16ToWideHack(tooltip_text_));
- return true;
- }
-
- // Show the full text if the text does not fit.
- if (!is_multi_line_ &&
- (font_.GetStringWidth(text_) > GetAvailableRect().width())) {
- *tooltip = UTF16ToWideHack(text_);
- return true;
- }
- return false;
-}
-
-void Label::OnMouseMoved(const MouseEvent& event) {
- UpdateContainsMouse(event);
-}
-
-void Label::OnMouseEntered(const MouseEvent& event) {
- UpdateContainsMouse(event);
-}
-
-void Label::OnMouseExited(const MouseEvent& event) {
- SetContainsMouse(false);
-}
-
void Label::SetMouseOverBackground(Background* background) {
mouse_over_background_.reset(background);
}
@@ -220,22 +138,6 @@ const Background* Label::GetMouseOverBackground() const {
return mouse_over_background_.get();
}
-void Label::SetEnabled(bool enabled) {
- if (enabled == enabled_)
- return;
- View::SetEnabled(enabled);
- SetColor(enabled ? kEnabledColor : kDisabledColor);
-}
-
-gfx::Insets Label::GetInsets() const {
- gfx::Insets insets = View::GetInsets();
- if (IsFocusable() || has_focus_border_) {
- insets += gfx::Insets(kFocusBorderPadding, kFocusBorderPadding,
- kFocusBorderPadding, kFocusBorderPadding);
- }
- return insets;
-}
-
void Label::SizeToFit(int max_width) {
DCHECK(is_multi_line_);
@@ -258,12 +160,6 @@ void Label::SizeToFit(int max_width) {
SizeToPreferredSize();
}
-void Label::GetAccessibleState(ui::AccessibleViewState* state) {
- state->role = ui::AccessibilityTypes::ROLE_STATICTEXT;
- state->state = ui::AccessibilityTypes::STATE_READONLY;
- state->name = text_;
-}
-
void Label::SetHasFocusBorder(bool has_focus_border) {
has_focus_border_ = has_focus_border;
if (is_multi_line_) {
@@ -272,6 +168,92 @@ void Label::SetHasFocusBorder(bool has_focus_border) {
}
}
+gfx::Insets Label::GetInsets() const {
+ gfx::Insets insets = View::GetInsets();
+ if (IsFocusable() || has_focus_border_) {
+ insets += gfx::Insets(kFocusBorderPadding, kFocusBorderPadding,
+ kFocusBorderPadding, kFocusBorderPadding);
+ }
+ return insets;
+}
+
+int Label::GetBaseline() {
+ return GetInsets().top() + font_.GetBaseline();
+}
+
+gfx::Size Label::GetPreferredSize() {
+ // Return a size of (0, 0) if the label is not visible and if the
+ // collapse_when_hidden_ flag is set.
+ // TODO(munjal): This logic probably belongs to the View class. But for now,
+ // put it here since putting it in View class means all inheriting classes
+ // need ot respect the collapse_when_hidden_ flag.
+ if (!IsVisible() && collapse_when_hidden_)
+ return gfx::Size();
+
+ gfx::Size prefsize(GetTextSize());
+ gfx::Insets insets = GetInsets();
+ prefsize.Enlarge(insets.width(), insets.height());
+ return prefsize;
+}
+
+int Label::GetHeightForWidth(int w) {
+ if (!is_multi_line_)
+ return View::GetHeightForWidth(w);
+
+ w = std::max(0, w - GetInsets().width());
+ int h = font_.GetHeight();
+ gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h,
+ ComputeMultiLineFlags());
+ return h + GetInsets().height();
+}
+
+void Label::SetEnabled(bool enabled) {
+ if (enabled == enabled_)
+ return;
+ View::SetEnabled(enabled);
+ SetColor(enabled ? kEnabledColor : kDisabledColor);
+}
+
+std::string Label::GetClassName() const {
+ return kViewClassName;
+}
+
+void Label::OnMouseMoved(const MouseEvent& event) {
+ UpdateContainsMouse(event);
+}
+
+void Label::OnMouseEntered(const MouseEvent& event) {
+ UpdateContainsMouse(event);
+}
+
+void Label::OnMouseExited(const MouseEvent& event) {
+ SetContainsMouse(false);
+}
+
+bool Label::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) {
+ DCHECK(tooltip);
+
+ // If a tooltip has been explicitly set, use it.
+ if (!tooltip_text_.empty()) {
+ tooltip->assign(UTF16ToWideHack(tooltip_text_));
+ return true;
+ }
+
+ // Show the full text if the text does not fit.
+ if (!is_multi_line_ &&
+ (font_.GetStringWidth(text_) > GetAvailableRect().width())) {
+ *tooltip = UTF16ToWideHack(text_);
+ return true;
+ }
+ return false;
+}
+
+void Label::GetAccessibleState(ui::AccessibleViewState* state) {
+ state->role = ui::AccessibilityTypes::ROLE_STATICTEXT;
+ state->state = ui::AccessibilityTypes::STATE_READONLY;
+ state->name = text_;
+}
+
void Label::PaintText(gfx::Canvas* canvas,
const std::wstring& text,
const gfx::Rect& text_bounds,
@@ -314,6 +296,24 @@ void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) {
text_size_valid_ &= !is_multi_line_;
}
+void Label::OnPaint(gfx::Canvas* canvas) {
+ OnPaintBackground(canvas);
+
+ std::wstring paint_text;
+ gfx::Rect text_bounds;
+ int flags = 0;
+ CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
+ PaintText(canvas, paint_text, text_bounds, flags);
+}
+
+void Label::OnPaintBackground(gfx::Canvas* canvas) {
+ const Background* bg = contains_mouse_ ? GetMouseOverBackground() : NULL;
+ if (!bg)
+ bg = background();
+ if (bg)
+ bg->Paint(canvas, this);
+}
+
// static
gfx::Font Label::GetDefaultFont() {
return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
diff --git a/views/controls/label.h b/views/controls/label.h
index 7d8c64d..c1ccb52 100644
--- a/views/controls/label.h
+++ b/views/controls/label.h
@@ -54,27 +54,6 @@ class Label : public View {
Label(const std::wstring& text, const gfx::Font& font);
virtual ~Label();
- // Overridden to compute the size required to display this label.
- virtual gfx::Size GetPreferredSize() OVERRIDE;
-
- // Overriden to return the baseline of the label.
- virtual int GetBaseline() OVERRIDE;
-
- // Return the height necessary to display this label with the provided width.
- // This method is used to layout multi-line labels. It is equivalent to
- // GetPreferredSize().height() if the receiver is not multi-line.
- virtual int GetHeightForWidth(int w);
-
- // Returns views/Label.
- virtual std::string GetClassName() const OVERRIDE;
-
- // Overridden to paint
- virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
-
- // If the mouse is over the label, and a mouse over background has been
- // specified, its used. Otherwise super's implementation is invoked.
- virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
-
// Set the font.
virtual void SetFont(const gfx::Font& font);
@@ -145,29 +124,11 @@ class Label : public View {
// default behavior, call this with an empty string.
void SetTooltipText(const std::wstring& tooltip_text);
- // Gets the tooltip text for labels that are wider than their bounds, except
- // when the label is multiline, in which case it just returns false (no
- // tooltip). If a custom tooltip has been specified with SetTooltipText()
- // it is returned instead.
- virtual bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip);
-
- // Mouse enter/exit are overridden to render mouse over background color.
- // These invoke SetContainsMouse as necessary.
- virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE;
- virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
-
// The background color to use when the mouse is over the label. Label
// takes ownership of the Background.
void SetMouseOverBackground(Background* background);
const Background* GetMouseOverBackground() const;
- // Sets the enabled state. Setting the enabled state resets the color.
- virtual void SetEnabled(bool enabled) OVERRIDE;
-
- // Overridden from View:
- virtual gfx::Insets GetInsets() const;
-
// Resizes the label so its width is set to the width of the longest line and
// its height deduced accordingly.
// This is only intended for multi-line labels and is useful when the label's
@@ -176,9 +137,6 @@ class Label : public View {
// wrapped). If 0, no maximum width is enforced.
void SizeToFit(int max_width);
- // Accessibility accessors, overridden from View.
- virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
-
// Gets/sets the flag to determine whether the label should be collapsed when
// it's hidden (not visible). If this flag is true, the label will return a
// preferred size of (0, 0) when it's not visible.
@@ -193,6 +151,30 @@ class Label : public View {
void SetHasFocusBorder(bool has_focus_border);
+ // Overridden from View:
+ virtual gfx::Insets GetInsets() const;
+ virtual int GetBaseline() OVERRIDE;
+ // Overridden to compute the size required to display this label.
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+ // Return the height necessary to display this label with the provided width.
+ // This method is used to layout multi-line labels. It is equivalent to
+ // GetPreferredSize().height() if the receiver is not multi-line.
+ virtual int GetHeightForWidth(int w);
+ // Sets the enabled state. Setting the enabled state resets the color.
+ virtual void SetEnabled(bool enabled) OVERRIDE;
+ virtual std::string GetClassName() const OVERRIDE;
+ // Mouse enter/exit are overridden to render mouse over background color.
+ // These invoke SetContainsMouse as necessary.
+ virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE;
+ virtual void OnMouseEntered(const MouseEvent& event) OVERRIDE;
+ virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
+ // Gets the tooltip text for labels that are wider than their bounds, except
+ // when the label is multiline, in which case it just returns false (no
+ // tooltip). If a custom tooltip has been specified with SetTooltipText()
+ // it is returned instead.
+ virtual bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip);
+ virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
+
protected:
// Called by Paint to paint the text. Override this to change how
// text is painted.
@@ -205,8 +187,13 @@ class Label : public View {
virtual gfx::Size GetTextSize() const;
- // Overriden to dirty our text bounds if we're multi-line.
+ // Overridden from View:
+ // Overridden to dirty our text bounds if we're multi-line.
virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
+ // If the mouse is over the label, and a mouse over background has been
+ // specified, its used. Otherwise super's implementation is invoked.
+ virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
private:
// These tests call CalculateDrawStringParams in order to verify the
diff --git a/views/controls/menu/menu_host_root_view.cc b/views/controls/menu/menu_host_root_view.cc
index bb791fc..bf2a997 100644
--- a/views/controls/menu/menu_host_root_view.cc
+++ b/views/controls/menu/menu_host_root_view.cc
@@ -66,12 +66,6 @@ void MenuHostRootView::OnMouseMoved(const MouseEvent& event) {
GetMenuController()->OnMouseMoved(submenu_, event);
}
-bool MenuHostRootView::OnMouseWheel(const MouseWheelEvent& event) {
- // RootView::OnMouseWheel forwards to the focused view. We don't have a
- // focused view, so we need to override this then forward to the menu.
- return submenu_->OnMouseWheel(event);
-}
-
void MenuHostRootView::OnMouseExited(const MouseEvent& event) {
if (suspend_events_)
return;
@@ -79,6 +73,12 @@ void MenuHostRootView::OnMouseExited(const MouseEvent& event) {
RootView::OnMouseExited(event);
}
+bool MenuHostRootView::OnMouseWheel(const MouseWheelEvent& event) {
+ // RootView::OnMouseWheel forwards to the focused view. We don't have a
+ // focused view, so we need to override this then forward to the menu.
+ return submenu_->OnMouseWheel(event);
+}
+
MenuController* MenuHostRootView::GetMenuController() {
return submenu_->GetMenuItem()->GetMenuController();
}
diff --git a/views/controls/menu/menu_host_root_view.h b/views/controls/menu/menu_host_root_view.h
index f989170..b8b8e34 100644
--- a/views/controls/menu/menu_host_root_view.h
+++ b/views/controls/menu/menu_host_root_view.h
@@ -24,16 +24,15 @@ class MenuHostRootView : public RootView {
MenuHostRootView(Widget* widget, SubmenuView* submenu);
// When invoked subsequent events are NOT forwarded to the MenuController.
- void suspend_events() {
- suspend_events_ = true;
- }
+ void suspend_events() { suspend_events_ = true; }
+ // Overridden from View:
virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE;
virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE;
virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE;
- virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE;
virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
+ virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE;
private:
// Returns the MenuController for this MenuHostRootView.
diff --git a/views/controls/scrollbar/bitmap_scroll_bar.cc b/views/controls/scrollbar/bitmap_scroll_bar.cc
index d41c332..beef8c4 100644
--- a/views/controls/scrollbar/bitmap_scroll_bar.cc
+++ b/views/controls/scrollbar/bitmap_scroll_bar.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// 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.
@@ -394,11 +394,6 @@ void BitmapScrollBar::ScrollByContentsOffset(int contents_offset) {
ScrollContentsToOffset();
}
-void BitmapScrollBar::TrackClicked() {
- if (last_scroll_amount_ != SCROLL_NONE)
- ScrollByAmount(last_scroll_amount_);
-}
-
///////////////////////////////////////////////////////////////////////////////
// BitmapScrollBar, View implementation:
@@ -409,14 +404,6 @@ gfx::Size BitmapScrollBar::GetPreferredSize() {
return gfx::Size(button_prefsize.width(), button_prefsize.height() * 2);
}
-void BitmapScrollBar::OnPaint(gfx::Canvas* canvas) {
- // Paint the track.
- gfx::Rect track_bounds = GetTrackBounds();
- canvas->TileImageInt(*images_[THUMB_TRACK][thumb_track_state_],
- track_bounds.x(), track_bounds.y(),
- track_bounds.width(), track_bounds.height());
-}
-
void BitmapScrollBar::Layout() {
// Size and place the two scroll buttons.
if (show_scroll_buttons_) {
@@ -490,11 +477,6 @@ void BitmapScrollBar::OnMouseReleased(const MouseEvent& event, bool canceled) {
View::OnMouseReleased(event, canceled);
}
-bool BitmapScrollBar::OnMouseWheel(const MouseWheelEvent& event) {
- ScrollByContentsOffset(event.offset());
- return true;
-}
-
bool BitmapScrollBar::OnKeyPressed(const KeyEvent& event) {
ScrollAmount amount = SCROLL_NONE;
switch (event.key_code()) {
@@ -534,6 +516,11 @@ bool BitmapScrollBar::OnKeyPressed(const KeyEvent& event) {
return false;
}
+bool BitmapScrollBar::OnMouseWheel(const MouseWheelEvent& event) {
+ ScrollByContentsOffset(event.offset());
+ return true;
+}
+
///////////////////////////////////////////////////////////////////////////////
// BitmapScrollBar, ContextMenuController implementation:
@@ -694,8 +681,24 @@ int BitmapScrollBar::GetPosition() const {
}
///////////////////////////////////////////////////////////////////////////////
+// BitmapScrollBar, View implementation:
+
+void BitmapScrollBar::OnPaint(gfx::Canvas* canvas) {
+ // Paint the track.
+ gfx::Rect track_bounds = GetTrackBounds();
+ canvas->TileImageInt(*images_[THUMB_TRACK][thumb_track_state_],
+ track_bounds.x(), track_bounds.y(),
+ track_bounds.width(), track_bounds.height());
+}
+
+///////////////////////////////////////////////////////////////////////////////
// BitmapScrollBar, private:
+void BitmapScrollBar::TrackClicked() {
+ if (last_scroll_amount_ != SCROLL_NONE)
+ ScrollByAmount(last_scroll_amount_);
+}
+
void BitmapScrollBar::ScrollContentsToOffset() {
GetController()->ScrollToPosition(this, contents_scroll_offset_);
thumb_->SetPosition(CalculateThumbPosition(contents_scroll_offset_));
diff --git a/views/controls/scrollbar/bitmap_scroll_bar.h b/views/controls/scrollbar/bitmap_scroll_bar.h
index 839e872..8357fd1 100644
--- a/views/controls/scrollbar/bitmap_scroll_bar.h
+++ b/views/controls/scrollbar/bitmap_scroll_bar.h
@@ -96,12 +96,11 @@ class BitmapScrollBar : public ScrollBar,
// View overrides:
virtual gfx::Size GetPreferredSize() OVERRIDE;
- virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual void Layout() OVERRIDE;
virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE;
- virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE;
virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE;
+ virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE;
// BaseButton::ButtonListener overrides:
virtual void ButtonPressed(Button* sender,
@@ -124,6 +123,10 @@ class BitmapScrollBar : public ScrollBar,
virtual bool IsCommandEnabled(int id) const OVERRIDE;
virtual void ExecuteCommand(int id) OVERRIDE;
+ protected:
+ // View overrides:
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
+
private:
// Called when the mouse is pressed down in the track area.
void TrackClicked();
diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc
index 0ce608c..f5ceffe 100644
--- a/views/widget/root_view.cc
+++ b/views/widget/root_view.cc
@@ -148,13 +148,6 @@ View* RootView::GetFocusTraversableParentView() {
////////////////////////////////////////////////////////////////////////////////
// RootView, View overrides:
-void RootView::SchedulePaintInRect(const gfx::Rect& rect) {
- gfx::Rect xrect = ConvertRectToParent(rect);
- gfx::Rect invalid_rect = GetLocalBounds().Intersect(xrect);
- if (!invalid_rect.IsEmpty())
- widget_->SchedulePaintInRect(invalid_rect);
-}
-
const Widget* RootView::GetWidget() const {
return widget_;
}
@@ -163,11 +156,19 @@ Widget* RootView::GetWidget() {
return const_cast<Widget*>(const_cast<const RootView*>(this)->GetWidget());
}
-void RootView::OnMouseExited(const MouseEvent& event) {
- if (mouse_move_handler_ != NULL) {
- mouse_move_handler_->OnMouseExited(event);
- mouse_move_handler_ = NULL;
- }
+bool RootView::IsVisibleInRootView() const {
+ return IsVisible();
+}
+
+std::string RootView::GetClassName() const {
+ return kViewClassName;
+}
+
+void RootView::SchedulePaintInRect(const gfx::Rect& rect) {
+ gfx::Rect xrect = ConvertRectToParent(rect);
+ gfx::Rect invalid_rect = GetLocalBounds().Intersect(xrect);
+ if (!invalid_rect.IsEmpty())
+ widget_->SchedulePaintInRect(invalid_rect);
}
bool RootView::OnMousePressed(const MouseEvent& event) {
@@ -307,10 +308,11 @@ void RootView::OnMouseMoved(const MouseEvent& event) {
}
}
-void RootView::SetMouseHandler(View *new_mh) {
- // If we're clearing the mouse handler, clear explicit_mouse_handler as well.
- explicit_mouse_handler_ = (new_mh != NULL);
- mouse_pressed_handler_ = new_mh;
+void RootView::OnMouseExited(const MouseEvent& event) {
+ if (mouse_move_handler_ != NULL) {
+ mouse_move_handler_->OnMouseExited(event);
+ mouse_move_handler_ = NULL;
+ }
}
bool RootView::OnMouseWheel(const MouseWheelEvent& event) {
@@ -385,21 +387,18 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& event) {
}
#endif
-bool RootView::IsVisibleInRootView() const {
- return IsVisible();
-}
-
-std::string RootView::GetClassName() const {
- return kViewClassName;
+void RootView::SetMouseHandler(View *new_mh) {
+ // If we're clearing the mouse handler, clear explicit_mouse_handler as well.
+ explicit_mouse_handler_ = (new_mh != NULL);
+ mouse_pressed_handler_ = new_mh;
}
void RootView::GetAccessibleState(ui::AccessibleViewState* state) {
state->role = ui::AccessibilityTypes::ROLE_APPLICATION;
}
-void RootView::OnPaint(gfx::Canvas* canvas) {
- canvas->AsCanvasSkia()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
-}
+////////////////////////////////////////////////////////////////////////////////
+// RootView, protected:
void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
widget_->ViewHierarchyChanged(is_add, parent, child);
@@ -416,8 +415,13 @@ void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
}
}
+
+void RootView::OnPaint(gfx::Canvas* canvas) {
+ canvas->AsCanvasSkia()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
+}
+
////////////////////////////////////////////////////////////////////////////////
-// RootView, protected:
+// RootView, private:
// Coordinate conversion -------------------------------------------------------
diff --git a/views/widget/root_view.h b/views/widget/root_view.h
index 6658fe0..b6f7662 100644
--- a/views/widget/root_view.h
+++ b/views/widget/root_view.h
@@ -99,28 +99,28 @@ class RootView : public View,
virtual View* GetFocusTraversableParentView() OVERRIDE;
// Overridden from View:
- virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
virtual const Widget* GetWidget() const OVERRIDE;
virtual Widget* GetWidget() OVERRIDE;
- virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
+ virtual bool IsVisibleInRootView() const OVERRIDE;
+ virtual std::string GetClassName() const OVERRIDE;
+ virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
virtual bool OnMouseDragged(const MouseEvent& event) OVERRIDE;
virtual void OnMouseReleased(const MouseEvent& event, bool canceled) OVERRIDE;
virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE;
- virtual void SetMouseHandler(View* new_mouse_handler) OVERRIDE;
+ virtual void OnMouseExited(const MouseEvent& event) OVERRIDE;
virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE;
#if defined(TOUCH_UI)
virtual TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE;
#endif
- virtual bool IsVisibleInRootView() const OVERRIDE;
- virtual std::string GetClassName() const OVERRIDE;
+ virtual void SetMouseHandler(View* new_mouse_handler) OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
protected:
// Overridden from View:
- virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual void ViewHierarchyChanged(bool is_add, View* parent,
View* child) OVERRIDE;
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
private:
friend class View;