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 #include "chrome/browser/bookmarks/bookmark_drop_info.h"
      6 
      7 #if defined(OS_WIN)
      8 #include <windows.h>
      9 #endif
     10 
     11 #include "base/basictypes.h"
     12 #include "views/events/event.h"
     13 #include "views/view_constants.h"
     14 
     15 BookmarkDropInfo::BookmarkDropInfo(gfx::NativeWindow wnd, int top_margin)
     16     : source_operations_(0),
     17       is_control_down_(false),
     18       last_y_(0),
     19       drop_operation_(0),
     20       wnd_(wnd),
     21       top_margin_(top_margin),
     22       scroll_up_(false) {
     23 }
     24 
     25 BookmarkDropInfo::~BookmarkDropInfo() {
     26 }
     27 
     28 void BookmarkDropInfo::Update(const views::DropTargetEvent& event) {
     29   source_operations_ = event.source_operations();
     30   is_control_down_ = event.IsControlDown();
     31   last_y_ = event.y();
     32 
     33 #if defined(OS_WIN)
     34   RECT client_rect;
     35   GetClientRect(wnd_, &client_rect);
     36   bool scroll_down = (last_y_ >= client_rect.bottom - views::kAutoscrollSize);
     37 #else
     38   // TODO(port): Get the dimensions of the appropriate view/widget.
     39   NOTIMPLEMENTED();
     40   bool scroll_down = false;
     41 #endif
     42   scroll_up_ = (last_y_ <= top_margin_ + views::kAutoscrollSize);
     43   if (scroll_up_ || scroll_down) {
     44     if (!scroll_timer_.IsRunning()) {
     45       scroll_timer_.Start(
     46           base::TimeDelta::FromMilliseconds(views::kAutoscrollRowTimerMS),
     47           this,
     48           &BookmarkDropInfo::Scroll);
     49     }
     50   } else {
     51     scroll_timer_.Stop();
     52   }
     53 }
     54 
     55 void BookmarkDropInfo::Scroll() {
     56 #if defined(OS_WIN)
     57   SendMessage(wnd_, WM_VSCROLL, scroll_up_ ? SB_LINEUP : SB_LINEDOWN, NULL);
     58   Scrolled();
     59 #else
     60   // TODO(port): Scroll the appropriate view/widget.
     61   NOTIMPLEMENTED();
     62 #endif
     63 }
     64