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