summaryrefslogtreecommitdiffstats
path: root/chrome/views/view_win.cc
blob: 41e97a9f7049c785067fbb4a8c635e78e6463215 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) 2009 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/views/view.h"

#include "app/gfx/chrome_canvas.h"
#include "base/scoped_handle.h"
#include "base/string_util.h"
#include "chrome/common/drag_drop_types.h"
#include "chrome/common/gfx/path.h"
#include "chrome/common/os_exchange_data.h"
#include "chrome/views/accessibility/view_accessibility_wrapper.h"
#include "chrome/views/border.h"
#include "chrome/views/widget/root_view.h"
#include "chrome/views/widget/widget.h"

namespace views {

FocusManager* View::GetFocusManager() {
  Widget* widget = GetWidget();
  if (!widget)
    return NULL;

  HWND hwnd = widget->GetNativeView();
  if (!hwnd)
    return NULL;

  return FocusManager::GetFocusManager(hwnd);
}

void View::DoDrag(const MouseEvent& e, int press_x, int press_y) {
  int drag_operations = GetDragOperations(press_x, press_y);
  if (drag_operations == DragDropTypes::DRAG_NONE)
    return;

  scoped_refptr<OSExchangeData> data = new OSExchangeData;
  WriteDragData(press_x, press_y, data.get());

  // Message the RootView to do the drag and drop. That way if we're removed
  // the RootView can detect it and avoid calling us back.
  RootView* root_view = GetRootView();
  root_view->StartDragForViewFromMouseEvent(this, data, drag_operations);
}

ViewAccessibilityWrapper* View::GetViewAccessibilityWrapper() {
  if (accessibility_.get() == NULL) {
    accessibility_.reset(new ViewAccessibilityWrapper(this));
  }
  return accessibility_.get();
}

bool View::HitTest(const gfx::Point& l) const {
  if (l.x() >= 0 && l.x() < static_cast<int>(width()) &&
      l.y() >= 0 && l.y() < static_cast<int>(height())) {
    if (HasHitTestMask()) {
      gfx::Path mask;
      GetHitTestMask(&mask);
      ScopedHRGN rgn(mask.CreateHRGN());
      return !!PtInRegion(rgn, l.x(), l.y());
    }
    // No mask, but inside our bounds.
    return true;
  }
  // Outside our bounds.
  return false;
}

HCURSOR View::GetCursorForPoint(Event::EventType event_type, int x, int y) {
  return NULL;
}

void View::Focus() {
  // Set the native focus to the root view window so it receives the keyboard
  // messages.
  FocusManager* focus_manager = GetFocusManager();
  if (focus_manager)
    focus_manager->FocusHWND(GetRootView()->GetWidget()->GetNativeView());
}

int View::GetHorizontalDragThreshold() {
  static int threshold = -1;
  if (threshold == -1)
    threshold = GetSystemMetrics(SM_CXDRAG) / 2;
  return threshold;
}

int View::GetVerticalDragThreshold() {
  static int threshold = -1;
  if (threshold == -1)
    threshold = GetSystemMetrics(SM_CYDRAG) / 2;
  return threshold;
}

}  // namespace views