summaryrefslogtreecommitdiffstats
path: root/athena/screen/screen_accelerator_handler.cc
blob: 90d990f278698f29ddc7a58399906d0efc7bfe24 (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
// Copyright 2014 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 "athena/screen/screen_accelerator_handler.h"

#include "athena/input/public/accelerator_manager.h"
#include "athena/screen/public/screen_manager.h"
#include "ui/events/event_constants.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"

namespace athena {
namespace {

enum Command {
  CMD_ROTATE_SCREEN,
};

const AcceleratorData accelerator_data[] = {
    {TRIGGER_ON_PRESS, ui::VKEY_F3,
     ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN,
     CMD_ROTATE_SCREEN, AF_NONE},
};

void HandleRotateScreen() {
  ScreenManager* screen_manager = ScreenManager::Get();
  gfx::Display::Rotation current_rotation =
      gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().rotation();
  if (current_rotation == gfx::Display::ROTATE_0)
    screen_manager->SetRotation(gfx::Display::ROTATE_90);
  else if (current_rotation == gfx::Display::ROTATE_90)
    screen_manager->SetRotation(gfx::Display::ROTATE_180);
  else if (current_rotation == gfx::Display::ROTATE_180)
    screen_manager->SetRotation(gfx::Display::ROTATE_270);
  else if (current_rotation == gfx::Display::ROTATE_270)
    screen_manager->SetRotation(gfx::Display::ROTATE_0);
}

}  // namespace

ScreenAcceleratorHandler::ScreenAcceleratorHandler() {
  AcceleratorManager::Get()->RegisterAccelerators(
      accelerator_data, arraysize(accelerator_data), this);
}

ScreenAcceleratorHandler::~ScreenAcceleratorHandler() {
}

bool ScreenAcceleratorHandler::IsCommandEnabled(int command_id) const {
  return true;
}

bool ScreenAcceleratorHandler::OnAcceleratorFired(
    int command_id,
    const ui::Accelerator& accelerator) {
  switch (command_id) {
    case CMD_ROTATE_SCREEN:
      HandleRotateScreen();
      return true;
  }
  return false;
}

}  // namesapce athena