Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / views / linux_ui / window_button_order_provider.cc
blob22b8ffd5f4fb0a16a0ecbe9ef55547bd74d240c2
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/views/window/window_button_order_provider.h"
7 #include "ui/views/linux_ui/linux_ui.h"
8 #include "ui/views/linux_ui/window_button_order_observer.h"
10 namespace views {
12 namespace {
14 class WindowButtonOrderObserverDelegate : public WindowButtonOrderProvider,
15 public WindowButtonOrderObserver {
16 public:
17 WindowButtonOrderObserverDelegate();
18 ~WindowButtonOrderObserverDelegate() override;
20 // WindowButtonOrderObserver:
21 void OnWindowButtonOrderingChange(
22 const std::vector<views::FrameButton>& leading_buttons,
23 const std::vector<views::FrameButton>& trailing_buttons) override;
25 private:
26 DISALLOW_COPY_AND_ASSIGN(WindowButtonOrderObserverDelegate);
29 ///////////////////////////////////////////////////////////////////////////////
30 // WindowButtonOrderObserverDelegate, public:
32 WindowButtonOrderObserverDelegate::WindowButtonOrderObserverDelegate() {
33 views::LinuxUI* ui = views::LinuxUI::instance();
34 if (ui)
35 ui->AddWindowButtonOrderObserver(this);
38 WindowButtonOrderObserverDelegate::~WindowButtonOrderObserverDelegate() {
39 views::LinuxUI* ui = views::LinuxUI::instance();
40 if (ui)
41 ui->RemoveWindowButtonOrderObserver(this);
44 void WindowButtonOrderObserverDelegate::OnWindowButtonOrderingChange(
45 const std::vector<views::FrameButton>& leading_buttons,
46 const std::vector<views::FrameButton>& trailing_buttons) {
47 SetWindowButtonOrder(leading_buttons, trailing_buttons);
50 } // namespace
52 // static
53 WindowButtonOrderProvider* WindowButtonOrderProvider::instance_ = NULL;
55 ///////////////////////////////////////////////////////////////////////////////
56 // WindowButtonOrderProvider, public:
58 // static
59 WindowButtonOrderProvider* WindowButtonOrderProvider::GetInstance() {
60 if (!instance_)
61 instance_ = new WindowButtonOrderObserverDelegate;
62 return instance_;
65 ///////////////////////////////////////////////////////////////////////////////
66 // WindowButtonOrderProvider, protected:
68 WindowButtonOrderProvider::WindowButtonOrderProvider() {
69 trailing_buttons_.push_back(views::FRAME_BUTTON_MINIMIZE);
70 trailing_buttons_.push_back(views::FRAME_BUTTON_MAXIMIZE);
71 trailing_buttons_.push_back(views::FRAME_BUTTON_CLOSE);
74 WindowButtonOrderProvider::~WindowButtonOrderProvider() {
77 void WindowButtonOrderProvider::SetWindowButtonOrder(
78 const std::vector<views::FrameButton>& leading_buttons,
79 const std::vector<views::FrameButton>& trailing_buttons) {
80 leading_buttons_ = leading_buttons;
81 trailing_buttons_ = trailing_buttons;
84 } // namespace views