Home | History | Annotate | Download | only in frame
      1 // Copyright (c) 2011 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/browser_frame_gtk.h"
      6 
      7 #include "base/logging.h"
      8 #include "chrome/browser/profiles/profile.h"
      9 #include "chrome/browser/themes/theme_service.h"
     10 #include "chrome/browser/themes/theme_service_factory.h"
     11 #include "chrome/browser/ui/status_bubble.h"
     12 #include "chrome/browser/ui/views/frame/app_panel_browser_frame_view.h"
     13 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"
     14 #include "chrome/browser/ui/views/frame/browser_root_view.h"
     15 #include "chrome/browser/ui/views/frame/browser_view.h"
     16 #include "ui/gfx/font.h"
     17 #include "views/widget/root_view.h"
     18 #include "views/window/hit_test.h"
     19 
     20 #if !defined(OS_CHROMEOS)
     21 // static (Factory method.)
     22 BrowserFrame* BrowserFrame::Create(BrowserView* browser_view,
     23                                    Profile* profile) {
     24   BrowserFrameGtk* frame = new BrowserFrameGtk(browser_view, profile);
     25   frame->InitBrowserFrame();
     26   return frame;
     27 }
     28 #endif
     29 
     30 // static
     31 const gfx::Font& BrowserFrame::GetTitleFont() {
     32   static gfx::Font *title_font = new gfx::Font();
     33   return *title_font;
     34 }
     35 
     36 BrowserFrameGtk::BrowserFrameGtk(BrowserView* browser_view, Profile* profile)
     37     : BrowserFrame(browser_view),
     38       WindowGtk(browser_view),
     39       ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)),
     40       browser_view_(browser_view) {
     41   set_native_browser_frame(this);
     42   browser_view_->set_frame(this);
     43   non_client_view()->SetFrameView(CreateFrameViewForWindow());
     44 }
     45 
     46 BrowserFrameGtk::~BrowserFrameGtk() {
     47 }
     48 
     49 void BrowserFrameGtk::InitBrowserFrame() {
     50   WindowGtk::InitWindow(NULL, gfx::Rect());
     51   // Don't focus anything on creation, selecting a tab will set the focus.
     52 }
     53 
     54 ////////////////////////////////////////////////////////////////////////////////
     55 // BrowserFrameGtk, NativeBrowserFrame implementation:
     56 
     57 views::NativeWindow* BrowserFrameGtk::AsNativeWindow() {
     58   return this;
     59 }
     60 
     61 const views::NativeWindow* BrowserFrameGtk::AsNativeWindow() const {
     62   return this;
     63 }
     64 
     65 BrowserNonClientFrameView* BrowserFrameGtk::CreateBrowserNonClientFrameView() {
     66   return browser::CreateBrowserNonClientFrameView(this, browser_view_);
     67 }
     68 
     69 int BrowserFrameGtk::GetMinimizeButtonOffset() const {
     70   NOTIMPLEMENTED();
     71   return 0;
     72 }
     73 
     74 ThemeProvider* BrowserFrameGtk::GetThemeProviderForFrame() const {
     75   // This is implemented for a different interface than GetThemeProvider is,
     76   // but they mean the same things.
     77   return GetThemeProvider();
     78 }
     79 
     80 bool BrowserFrameGtk::AlwaysUseNativeFrame() const {
     81   return false;
     82 }
     83 
     84 void BrowserFrameGtk::TabStripDisplayModeChanged() {
     85   if (GetRootView()->has_children()) {
     86     // Make sure the child of the root view gets Layout again.
     87     GetRootView()->GetChildViewAt(0)->InvalidateLayout();
     88   }
     89   GetRootView()->Layout();
     90 }
     91 
     92 ////////////////////////////////////////////////////////////////////////////////
     93 // BrowserFrameGtk, WindowGtk overrides :
     94 
     95 ThemeProvider* BrowserFrameGtk::GetThemeProvider() const {
     96   return ThemeServiceFactory::GetForProfile(
     97       browser_view_->browser()->profile());
     98 }
     99 
    100 void BrowserFrameGtk::SetInitialFocus() {
    101   browser_view_->RestoreFocus();
    102 }
    103 
    104 views::RootView* BrowserFrameGtk::CreateRootView() {
    105   return delegate_->DelegateCreateRootView();
    106 }
    107 
    108 bool BrowserFrameGtk::GetAccelerator(int cmd_id,
    109                                      ui::Accelerator* accelerator) {
    110   return browser_view_->GetAccelerator(cmd_id, accelerator);
    111 }
    112 
    113 views::NonClientFrameView* BrowserFrameGtk::CreateFrameViewForWindow() {
    114   return delegate_->DelegateCreateFrameViewForWindow();
    115 }
    116 
    117 gboolean BrowserFrameGtk::OnWindowStateEvent(GtkWidget* widget,
    118                                              GdkEventWindowState* event) {
    119   bool was_full_screen = IsFullscreen();
    120   gboolean result = views::WindowGtk::OnWindowStateEvent(widget, event);
    121   if ((!IsVisible() || IsMinimized()) && browser_view_->GetStatusBubble()) {
    122     // The window is effectively hidden. We have to hide the status bubble as
    123     // unlike windows gtk has no notion of child windows that are hidden along
    124     // with the parent.
    125     browser_view_->GetStatusBubble()->Hide();
    126   }
    127   if (was_full_screen != IsFullscreen())
    128     browser_view_->FullScreenStateChanged();
    129   return result;
    130 }
    131 
    132 gboolean BrowserFrameGtk::OnConfigureEvent(GtkWidget* widget,
    133                                            GdkEventConfigure* event) {
    134   browser_view_->WindowMoved();
    135   return views::WindowGtk::OnConfigureEvent(widget, event);
    136 }
    137