summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-22 22:00:09 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-22 22:00:09 +0000
commitbd5a00a743c92290ec01d6ea603a5fd96098093e (patch)
treee2db07ba7b8f7e75911e5dede215bb9551216450 /views
parenta26b7d4950c1e684ab1620674a335ff3a27eda5c (diff)
downloadchromium_src-bd5a00a743c92290ec01d6ea603a5fd96098093e.zip
chromium_src-bd5a00a743c92290ec01d6ea603a5fd96098093e.tar.gz
chromium_src-bd5a00a743c92290ec01d6ea603a5fd96098093e.tar.bz2
Resize and overflow for browser actions (part 1).
This changelist implements the following: - A resize gripper and chevron in the browser action container - Overflow when icons don't fit - Snap to multiple of icon size (no excess pixels) - Animation when resizing container / adding&removing icons (disable, enable). - Persists the last width of the browser action container. Known issues: - No menu (yes, the chevron button doesn't do anything yet). BUG=32101 TEST=Install and uninstall browser actions & make sure install bubble appears in the right location. Make sure browser action container does not expand if chevron is showing when you add browser action. Make sure container loses chevron when no overflow occurs. Make sure browser action icons never disappear due to shrinking when you release the mouse (when resizing). Make sure snapping works. Review URL: http://codereview.chromium.org/553039 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36905 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/resize_gripper.cc85
-rw-r--r--views/controls/resize_gripper.h60
-rw-r--r--views/views.gyp2
3 files changed, 147 insertions, 0 deletions
diff --git a/views/controls/resize_gripper.cc b/views/controls/resize_gripper.cc
new file mode 100644
index 0000000..f443f33
--- /dev/null
+++ b/views/controls/resize_gripper.cc
@@ -0,0 +1,85 @@
+// Copyright (c) 2010 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/resize_gripper.h"
+
+#include "base/logging.h"
+#include "app/resource_bundle.h"
+#include "grit/app_resources.h"
+
+namespace views {
+
+const char ResizeGripper::kViewClassName[] = "views/ResizeGripper";
+
+#if defined(OS_WIN)
+static HCURSOR g_resize_cursor = NULL;
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+// ResizeGripper
+
+ResizeGripper::ResizeGripper(ResizeGripperDelegate* delegate)
+ : delegate_(delegate), initial_position_(0) {
+ ResourceBundle &rb = ResourceBundle::GetSharedInstance();
+ SkBitmap* gripper_image = rb.GetBitmapNamed(IDR_RESIZE_GRIPPER);
+ SetImage(gripper_image);
+}
+
+ResizeGripper::~ResizeGripper() {
+}
+
+std::string ResizeGripper::GetClassName() const {
+ return kViewClassName;
+}
+
+gfx::NativeCursor ResizeGripper::GetCursorForPoint(Event::EventType event_type,
+ int x, int y) {
+ if (!enabled_)
+ return NULL;
+#if defined(OS_WIN)
+ if (!g_resize_cursor)
+ g_resize_cursor = LoadCursor(NULL, IDC_SIZEWE);
+ return g_resize_cursor;
+#elif defined(OS_LINUX)
+ return gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW);
+#endif
+}
+
+bool ResizeGripper::OnMousePressed(const views::MouseEvent& event) {
+ if (!event.IsOnlyLeftMouseButton())
+ return false;
+
+ // The resize gripper obviously will move once you start dragging so we need
+ // to convert coordinates to screen coordinates so that we don't loose our
+ // bearings.
+ gfx::Point point(event.x(), 0);
+ View::ConvertPointToScreen(this, &point);
+ initial_position_ = point.x();
+
+ return true;
+}
+
+bool ResizeGripper::OnMouseDragged(const views::MouseEvent& event) {
+ if (!event.IsLeftMouseButton())
+ return false;
+
+ gfx::Point point(event.x(), 0);
+ View::ConvertPointToScreen(this, &point);
+
+ delegate_->OnResize(point.x() - initial_position_, false);
+ return true;
+}
+
+void ResizeGripper::OnMouseReleased(const views::MouseEvent& event,
+ bool canceled) {
+ gfx::Point point(event.x(), 0);
+ View::ConvertPointToScreen(this, &point);
+
+ if (canceled)
+ delegate_->OnResize(0, true);
+ else
+ delegate_->OnResize(point.x() - initial_position_, true);
+}
+
+} // namespace views
diff --git a/views/controls/resize_gripper.h b/views/controls/resize_gripper.h
new file mode 100644
index 0000000..1b65066
--- /dev/null
+++ b/views/controls/resize_gripper.h
@@ -0,0 +1,60 @@
+// Copyright (c) 2010 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_RESIZE_GRIPPER_H_
+#define VIEWS_CONTROLS_RESIZE_GRIPPER_H_
+
+#include <string>
+
+#include "views/controls/image_view.h"
+
+namespace views {
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// A simple resize gripper (two vertical bars).
+//
+////////////////////////////////////////////////////////////////////////////////
+class ResizeGripper : public ImageView {
+ public:
+ //////////////////////////////////////////////////////////////////////////////
+ //
+ // The interface needed for getting notified about the resize event.
+ //
+ //////////////////////////////////////////////////////////////////////////////
+ class ResizeGripperDelegate {
+ public:
+ // OnResize is sent when resizing is detected. |resize_amount| specifies the
+ // number of pixels that the user wants to resize by, and can be negative or
+ // positive (depending on direction of dragging). |done_resizing| is
+ // true if the user has released the mouse.
+ virtual void OnResize(int resize_amount, bool done_resizing) = 0;
+ };
+
+ explicit ResizeGripper(ResizeGripperDelegate* delegate);
+ virtual ~ResizeGripper();
+
+ // Overridden from views::View:
+ virtual std::string GetClassName() const;
+ virtual gfx::NativeCursor GetCursorForPoint(Event::EventType event_type,
+ int x, int y);
+ virtual bool OnMousePressed(const views::MouseEvent& event);
+ virtual bool OnMouseDragged(const views::MouseEvent& event);
+ virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled);
+
+ static const char kViewClassName[];
+
+ private:
+ // The delegate to notify when we have updates.
+ ResizeGripperDelegate* delegate_;
+
+ // The mouse position at start (in screen coordinates).
+ int initial_position_;
+
+ DISALLOW_COPY_AND_ASSIGN(ResizeGripper);
+};
+
+} // namespace views
+
+#endif // VIEWS_CONTROLS_RESIZE_GRIPPER_H_
diff --git a/views/views.gyp b/views/views.gyp
index 2697eec..bfab674 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -151,6 +151,8 @@
'controls/native/native_view_host_win.cc',
'controls/native/native_view_host_win.h',
'controls/native/native_view_host_wrapper.h',
+ 'controls/resize_gripper.cc',
+ 'controls/resize_gripper.h',
'controls/scroll_view.cc',
'controls/scroll_view.h',
'controls/scrollbar/bitmap_scroll_bar.cc',