summaryrefslogtreecommitdiffstats
path: root/ui/views/events/event.cc
blob: f1d04b9a7fcd38cff09ddced45dc6ba940fbdfbe (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
// Copyright (c) 2011 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 "ui/views/events/event.h"

#include "ui/views/view.h"

namespace ui {

////////////////////////////////////////////////////////////////////////////////
// Event, protected:

Event::Event(EventType type, int flags)
    : type_(type),
      flags_(flags) {
}

int Event::GetModifiers() const {
  int modifiers = 0;
  if (IsShiftDown())
    modifiers |= VKEY_SHIFT;
  if (IsControlDown())
    modifiers |= VKEY_CONTROL;
  if (IsAltDown())
    modifiers |= VKEY_MENU;
  if (IsCapsLockDown())
    modifiers |= VKEY_CAPITAL;
  return modifiers;
}

////////////////////////////////////////////////////////////////////////////////
// LocatedEvent, protected:

LocatedEvent::LocatedEvent(EventType type,
                           const gfx::Point& location,
                           int flags)
    : Event(type, flags),
      location_(location) {
}

LocatedEvent::LocatedEvent(const LocatedEvent& other,
                           View* source,
                           View* target)
    : Event(other.type(), other.flags()) {
  location_ = other.location();
  View::ConvertPointToView(source, target, &location_);
}

////////////////////////////////////////////////////////////////////////////////
// MouseEvent, public:

MouseEvent::MouseEvent(const MouseEvent& other, View* source, View* target)
    : LocatedEvent(other, source, target) {
}

}  // namespace views