1d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// found in the LICENSE file.
4d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
5d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/browser/ui/views/frame/opaque_browser_frame_view_linux.h"
6d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
7d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h"
8d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h"
9d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/views/linux_ui/linux_ui.h"
10d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
11d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)///////////////////////////////////////////////////////////////////////////////
12d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// OpaqueBrowserFrameViewLinux, public:
13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
14d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)OpaqueBrowserFrameViewLinux::OpaqueBrowserFrameViewLinux(
15d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    OpaqueBrowserFrameView* view,
16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    OpaqueBrowserFrameViewLayout* layout)
17d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    : view_(view),
18d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      layout_(layout) {
19d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  views::LinuxUI* ui = views::LinuxUI::instance();
20d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (ui)
21d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    ui->AddWindowButtonOrderObserver(this);
22d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)OpaqueBrowserFrameViewLinux::~OpaqueBrowserFrameViewLinux() {
25d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  views::LinuxUI* ui = views::LinuxUI::instance();
26d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (ui)
27d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    ui->RemoveWindowButtonOrderObserver(this);
28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
29d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
30d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)///////////////////////////////////////////////////////////////////////////////
31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// OpaqueBrowserFrameViewLinux,
32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)//     OpaqueBrowserFrameViewPlatformSpecific implementation:
33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool OpaqueBrowserFrameViewLinux::ShouldShowCaptionButtons() const {
35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // On Ubuntu Unity, if the window is maximized, the system will provide
36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // caption buttons, so Chrome should not add its own.
37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  views::LinuxUI* ui = views::LinuxUI::instance();
38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return !(view_->IsMaximized() && ui && ui->UnityIsRunning());
39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
41a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)///////////////////////////////////////////////////////////////////////////////
42d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// OpaqueBrowserFrameViewLinux,
43d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)//     views::WindowButtonOrderObserver implementation:
44d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
45d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void OpaqueBrowserFrameViewLinux::OnWindowButtonOrderingChange(
46d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    const std::vector<views::FrameButton>& leading_buttons,
47d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    const std::vector<views::FrameButton>& trailing_buttons) {
48d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  layout_->SetButtonOrdering(leading_buttons, trailing_buttons);
49d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
50d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // We can receive OnWindowButtonOrderingChange events before we've been added
51d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // to a Widget. We need a Widget because layout crashes due to dependencies
52d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // on a ui::ThemeProvider().
53d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  if (view_->GetWidget()) {
54d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    view_->Layout();
55d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    view_->SchedulePaint();
56d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
57d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
58d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
59d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)///////////////////////////////////////////////////////////////////////////////
60d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// OpaqueBrowserFrameViewObserver:
61d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
62d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// static
63d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)OpaqueBrowserFrameViewPlatformSpecific*
64d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)OpaqueBrowserFrameViewPlatformSpecific::Create(
65d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      OpaqueBrowserFrameView* view,
66d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      OpaqueBrowserFrameViewLayout* layout) {
67d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  return new OpaqueBrowserFrameViewLinux(view, layout);
68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
69