summaryrefslogtreecommitdiffstats
path: root/ui/aura/root_window.cc
blob: 1f3944026fa6f20b4f3b588b5fd73a8f90d8ca17 (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
// 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/aura/root_window.h"

#include "base/logging.h"
#include "ui/aura/event.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/window_delegate.h"
#include "ui/base/events.h"

namespace aura {
namespace internal {

RootWindow::RootWindow()
    : Window(NULL),
      mouse_pressed_handler_(NULL),
      ALLOW_THIS_IN_INITIALIZER_LIST(focus_manager_(new FocusManager(this))) {
}

RootWindow::~RootWindow() {
}

bool RootWindow::HandleMouseEvent(const MouseEvent& event) {
  Window* target = mouse_pressed_handler_;
  if (!target)
    target = GetEventHandlerForPoint(event.location());
  if (event.type() == ui::ET_MOUSE_PRESSED && !mouse_pressed_handler_)
    mouse_pressed_handler_ = target;
  if (event.type() == ui::ET_MOUSE_RELEASED)
    mouse_pressed_handler_ = NULL;
  if (target->delegate()) {
    MouseEvent translated_event(event, this, target);
    return target->OnMouseEvent(&translated_event);
  }
  return false;
}

bool RootWindow::HandleKeyEvent(const KeyEvent& event) {
  Window* focused_window = GetFocusManager()->focused_window();
  if (focused_window) {
    KeyEvent translated_event(event);
    return GetFocusManager()->focused_window()->OnKeyEvent(&translated_event);
  }
  return false;
}

bool RootWindow::IsTopLevelWindowContainer() const {
  return true;
}

FocusManager* RootWindow::GetFocusManager() {
  return focus_manager_.get();
}

}  // namespace internal
}  // namespace aura