Home | History | Annotate | Download | only in bookmarks
      1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_DROP_INFO_H_
      6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_DROP_INFO_H_
      7 #pragma once
      8 
      9 #include "base/basictypes.h"
     10 #include "base/timer.h"
     11 #include "chrome/browser/bookmarks/bookmark_node_data.h"
     12 #include "ui/gfx/native_widget_types.h"
     13 
     14 namespace views {
     15 class DropTargetEvent;
     16 }
     17 
     18 // BookmarkDropInfo is a pure virtual class that provides auto-scrolling
     19 // behavior and a handful of fields used for managing a bookmark drop.
     20 // BookmarkDropInfo is used by both BookmarkTableView and
     21 // BookmarksFolderTreeView.
     22 class BookmarkDropInfo {
     23  public:
     24   BookmarkDropInfo(gfx::NativeWindow hwnd, int top_margin);
     25   virtual ~BookmarkDropInfo();
     26 
     27   // Invoke this from OnDragUpdated. It resets source_operations,
     28   // is_control_down, last_y and updates the autoscroll timer as necessary.
     29   void Update(const views::DropTargetEvent& event);
     30 
     31   // Data from the drag.
     32   void SetData(const BookmarkNodeData& data) { data_ = data; }
     33   BookmarkNodeData& data() { return data_; }
     34 
     35   // Value of event.GetSourceOperations when Update was last invoked.
     36   int source_operations() const { return source_operations_; }
     37 
     38   // Whether the control key was down last time Update was invoked.
     39   bool is_control_down() const { return is_control_down_; }
     40 
     41   // Y position of the event last passed to Update.
     42   int last_y() { return last_y_; }
     43 
     44   // The drop operation that should occur. This is not updated by
     45   // BookmarkDropInfo, but provided for subclasses.
     46   void set_drop_operation(int drop_operation) {
     47     drop_operation_ = drop_operation;
     48   }
     49   int drop_operation() const { return drop_operation_; }
     50 
     51  protected:
     52   // Invoked if we autoscroll. When invoked subclasses need to determine
     53   // whether the drop is valid again as what is under the mouse has likely
     54   // scrolled.
     55   virtual void Scrolled() = 0;
     56 
     57  private:
     58   // Invoked from the timer. Scrolls up/down a line.
     59   void Scroll();
     60 
     61   BookmarkNodeData data_;
     62 
     63   int source_operations_;
     64 
     65   bool is_control_down_;
     66 
     67   int last_y_;
     68 
     69   int drop_operation_;
     70 
     71   gfx::NativeWindow wnd_;
     72 
     73   // Margin in addition to views::kAutoscrollSize that the mouse is allowed to
     74   // be over before we autoscroll.
     75   int top_margin_;
     76 
     77   // When autoscrolling this determines if we're scrolling up or down.
     78   bool scroll_up_;
     79 
     80   // Used when autoscrolling.
     81   base::RepeatingTimer<BookmarkDropInfo> scroll_timer_;
     82 
     83   DISALLOW_COPY_AND_ASSIGN(BookmarkDropInfo);
     84 };
     85 
     86 #endif  // CHROME_BROWSER_BOOKMARKS_BOOKMARK_DROP_INFO_H_
     87