summaryrefslogtreecommitdiffstats
path: root/chrome/browser/bookmarks/bookmark_drop_info.cc
blob: 646b35b2c5c6c33e343166505732ca9571157206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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();
}