summaryrefslogtreecommitdiffstats
path: root/chrome/browser/bookmarks
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-04 19:29:08 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-04 19:29:08 +0000
commitf28cbb7246977eb443650f7d2fc9675b573317b2 (patch)
treedda1262734dd45010df771821e869b687b9d1b6a /chrome/browser/bookmarks
parent431c16ea953a80b9153ba9a8c0b17b07a96f4a24 (diff)
downloadchromium_src-f28cbb7246977eb443650f7d2fc9675b573317b2.zip
chromium_src-f28cbb7246977eb443650f7d2fc9675b573317b2.tar.gz
chromium_src-f28cbb7246977eb443650f7d2fc9675b573317b2.tar.bz2
Adds support for autoscrolling on drag to bookmark tree/table.
BUG=674 TEST=none Review URL: http://codereview.chromium.org/9042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4625 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks')
-rw-r--r--chrome/browser/bookmarks/bookmark_drop_info.cc44
-rw-r--r--chrome/browser/bookmarks/bookmark_drop_info.h85
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.cc5
-rw-r--r--chrome/browser/bookmarks/bookmark_utils.h12
4 files changed, 135 insertions, 11 deletions
diff --git a/chrome/browser/bookmarks/bookmark_drop_info.cc b/chrome/browser/bookmarks/bookmark_drop_info.cc
new file mode 100644
index 0000000..646b35b
--- /dev/null
+++ b/chrome/browser/bookmarks/bookmark_drop_info.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2006-2008 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 "chrome/browser/bookmarks/bookmark_drop_info.h"
+
+#include "chrome/views/event.h"
+#include "chrome/views/view_constants.h"
+
+BookmarkDropInfo::BookmarkDropInfo(HWND hwnd, int top_margin)
+ : source_operations_(0),
+ is_control_down_(false),
+ last_y_(0),
+ drop_operation_(0),
+ hwnd_(hwnd),
+ top_margin_(top_margin),
+ scroll_up_(false) {
+}
+
+void BookmarkDropInfo::Update(const views::DropTargetEvent& event) {
+ source_operations_ = event.GetSourceOperations();
+ is_control_down_ = event.IsControlDown();
+ last_y_ = event.y();
+
+ RECT client_rect;
+ GetClientRect(hwnd_, &client_rect);
+ scroll_up_ = (last_y_ <= top_margin_ + views::kAutoscrollSize);
+ bool scroll_down = (last_y_ >= client_rect.bottom - views::kAutoscrollSize);
+ if (scroll_up_ || scroll_down) {
+ if (!scroll_timer_.IsRunning()) {
+ scroll_timer_.Start(
+ base::TimeDelta::FromMilliseconds(views::kAutoscrollRowTimerMS),
+ this,
+ &BookmarkDropInfo::Scroll);
+ }
+ } else {
+ scroll_timer_.Stop();
+ }
+}
+
+void BookmarkDropInfo::Scroll() {
+ SendMessage(hwnd_, WM_VSCROLL, scroll_up_ ? SB_LINEUP : SB_LINEDOWN, NULL);
+ Scrolled();
+}
diff --git a/chrome/browser/bookmarks/bookmark_drop_info.h b/chrome/browser/bookmarks/bookmark_drop_info.h
new file mode 100644
index 0000000..f4daf89
--- /dev/null
+++ b/chrome/browser/bookmarks/bookmark_drop_info.h
@@ -0,0 +1,85 @@
+// Copyright (c) 2006-2008 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 CHROME_BROWSER_BOOKMARKS_BOOKMARK_DROP_INFO_H_
+#define CHROME_BROWSER_BOOKMARKS_BOOKMARK_DROP_INFO_H_
+
+#include <windows.h>
+
+#include "base/timer.h"
+#include "chrome/browser/bookmarks/bookmark_drag_data.h"
+
+namespace views {
+class DropTargetEvent;
+}
+
+// BookmarkDropInfo is a pure virtual class that provides auto-scrolling
+// behavior and a handful of fields used for managing a bookmark drop.
+// BookmarkDropInfo is used by both BookmarkTableView and
+// BookmarksFolderTreeView.
+class BookmarkDropInfo {
+ public:
+ BookmarkDropInfo(HWND hwnd, int top_margin);
+ virtual ~BookmarkDropInfo() {}
+
+ // Invoke this from OnDragUpdated. It resets source_operations,
+ // is_control_down, last_y and updates the autoscroll timer as necessary.
+ void Update(const views::DropTargetEvent& event);
+
+ // Data from the drag.
+ void SetData(const BookmarkDragData& data) { data_ = data; }
+ BookmarkDragData& data() { return data_; }
+
+ // Value of event.GetSourceOperations when Update was last invoked.
+ int source_operations() const { return source_operations_; }
+
+ // Whether the control key was down last time Update was invoked.
+ bool is_control_down() const { return is_control_down_; }
+
+ // Y position of the event last passed to Update.
+ int last_y() { return last_y_; }
+
+ // The drop operation that should occur. This is not updated by
+ // BookmarkDropInfo, but provided for subclasses.
+ void set_drop_operation(int drop_operation) {
+ drop_operation_ = drop_operation;
+ }
+ int drop_operation() const { return drop_operation_; }
+
+ protected:
+ // Invoked if we autoscroll. When invoked subclasses need to determine
+ // whether the drop is valid again as what is under the mouse has likely
+ // scrolled.
+ virtual void Scrolled() = 0;
+
+ private:
+ // Invoked from the timer. Scrolls up/down a line.
+ void Scroll();
+
+ BookmarkDragData data_;
+
+ int source_operations_;
+
+ bool is_control_down_;
+
+ int last_y_;
+
+ int drop_operation_;
+
+ HWND hwnd_;
+
+ // Margin in addition to views::kAutoscrollSize that the mouse is allowed to
+ // be over before we autoscroll.
+ int top_margin_;
+
+ // When autoscrolling this determines if we're scrolling up or down.
+ bool scroll_up_;
+
+ // Used when autoscrolling.
+ base::RepeatingTimer<BookmarkDropInfo> scroll_timer_;
+
+ DISALLOW_COPY_AND_ASSIGN(BookmarkDropInfo);
+};
+
+#endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_DROP_INFO_H_
diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc
index d9b0be1..bf2576f 100644
--- a/chrome/browser/bookmarks/bookmark_utils.cc
+++ b/chrome/browser/bookmarks/bookmark_utils.cc
@@ -146,9 +146,8 @@ bool ShouldOpenAll(HWND parent, const std::vector<BookmarkNode*>& nodes) {
namespace bookmark_utils {
-int PreferredDropOperation(const views::DropTargetEvent& event,
- int operation) {
- int common_ops = (event.GetSourceOperations() & operation);
+int PreferredDropOperation(int source_operations, int operations) {
+ int common_ops = (source_operations & operations);
if (!common_ops)
return 0;
if (DragDropTypes::DRAG_COPY & common_ops)
diff --git a/chrome/browser/bookmarks/bookmark_utils.h b/chrome/browser/bookmarks/bookmark_utils.h
index 0711638..281cf8c 100644
--- a/chrome/browser/bookmarks/bookmark_utils.h
+++ b/chrome/browser/bookmarks/bookmark_utils.h
@@ -14,18 +14,14 @@ class BookmarkNode;
class PageNavigator;
class Profile;
-namespace views {
-class DropTargetEvent;
-}
-
// A collection of bookmark utility functions used by various parts of the UI
// that show bookmarks: bookmark manager, bookmark bar view ...
namespace bookmark_utils {
-// Calculates the drop operation given the event and supported set of
-// operations. This prefers the following ordering: COPY, LINK then MOVE.
-int PreferredDropOperation(const views::DropTargetEvent& event,
- int operation);
+// Calculates the drop operation given |source_operations| and the ideal
+// set of drop operations (|operations|). This prefers the following ordering:
+// COPY, LINK then MOVE.
+int PreferredDropOperation(int source_operations, int operations);
// Returns true if the bookmark data can be dropped on |drop_parent| at
// |index|. A drop from a separate profile is always allowed, where as