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

Unified Diff: views/controls/button/custom_button.cc

Issue 3198005: Disable the stop button when the user is hovering it and the page finishes lo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « views/controls/button/custom_button.h ('k') | views/widget/root_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/controls/button/custom_button.cc
===================================================================
--- views/controls/button/custom_button.cc (revision 56775)
+++ views/controls/button/custom_button.cc (working copy)
@@ -6,6 +6,7 @@
#include "app/throb_animation.h"
#include "base/keyboard_codes.h"
+#include "views/screen.h"
namespace views {
@@ -71,8 +72,13 @@
}
void CustomButton::SetEnabled(bool enabled) {
- if (enabled ? (state_ == BS_DISABLED) : (state_ != BS_DISABLED))
- SetState(enabled ? BS_NORMAL : BS_DISABLED);
+ if (enabled ? (state_ != BS_DISABLED) : (state_ == BS_DISABLED))
+ return;
+
+ if (enabled)
+ SetState(IsMouseHovered() ? BS_HOT : BS_NORMAL);
+ else
+ SetState(BS_DISABLED);
}
bool CustomButton::IsEnabled() const {
@@ -83,6 +89,17 @@
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);
+}
+
////////////////////////////////////////////////////////////////////////////////
// CustomButton, protected:
« no previous file with comments | « views/controls/button/custom_button.h ('k') | views/widget/root_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698