1 // Copyright (c) 2012 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 "chrome/browser/ui/views/frame/browser_desktop_window_tree_host_x11.h"
7 #include "chrome/browser/themes/theme_service.h"
8 #include "chrome/browser/themes/theme_service_factory.h"
9 #include "chrome/browser/ui/views/frame/browser_frame.h"
10 #include "chrome/browser/ui/views/frame/browser_view.h"
11 #include "chrome/browser/ui/views/theme_image_mapper.h"
15 // DesktopThemeProvider maps resource ids using MapThemeImage(). This is
16 // necessary for BrowserDesktopWindowTreeHostWin so that it uses the windows
17 // theme images rather than the ash theme images.
19 // This differs from the version in browser_desktop_window_tree_host_win.cc
20 // because we need to also look up whether we're using the native theme.
21 class DesktopThemeProvider
: public ui::ThemeProvider
{
23 explicit DesktopThemeProvider(ThemeService
* delegate
)
24 : delegate_(delegate
) {
27 virtual bool UsingSystemTheme() const OVERRIDE
{
28 return delegate_
->UsingSystemTheme();
30 virtual gfx::ImageSkia
* GetImageSkiaNamed(int id
) const OVERRIDE
{
31 if (delegate_
->UsingSystemTheme())
32 return delegate_
->GetImageSkiaNamed(id
);
34 return delegate_
->GetImageSkiaNamed(
35 chrome::MapThemeImage(chrome::HOST_DESKTOP_TYPE_NATIVE
, id
));
37 virtual SkColor
GetColor(int id
) const OVERRIDE
{
38 return delegate_
->GetColor(id
);
40 virtual int GetDisplayProperty(int id
) const OVERRIDE
{
41 return delegate_
->GetDisplayProperty(id
);
43 virtual bool ShouldUseNativeFrame() const OVERRIDE
{
44 return delegate_
->ShouldUseNativeFrame();
46 virtual bool HasCustomImage(int id
) const OVERRIDE
{
47 return delegate_
->HasCustomImage(
48 chrome::MapThemeImage(chrome::HOST_DESKTOP_TYPE_NATIVE
, id
));
50 virtual base::RefCountedMemory
* GetRawData(
52 ui::ScaleFactor scale_factor
) const OVERRIDE
{
53 return delegate_
->GetRawData(id
, scale_factor
);
57 ThemeService
* delegate_
;
59 DISALLOW_COPY_AND_ASSIGN(DesktopThemeProvider
);
64 ////////////////////////////////////////////////////////////////////////////////
65 // BrowserDesktopWindowTreeHostX11, public:
67 BrowserDesktopWindowTreeHostX11::BrowserDesktopWindowTreeHostX11(
68 views::internal::NativeWidgetDelegate
* native_widget_delegate
,
69 views::DesktopNativeWidgetAura
* desktop_native_widget_aura
,
70 BrowserView
* browser_view
,
71 BrowserFrame
* browser_frame
)
72 : DesktopWindowTreeHostX11(native_widget_delegate
,
73 desktop_native_widget_aura
),
74 browser_view_(browser_view
) {
75 scoped_ptr
<ui::ThemeProvider
> theme_provider(
76 new DesktopThemeProvider(ThemeServiceFactory::GetForProfile(
77 browser_view
->browser()->profile())));
78 browser_frame
->SetThemeProvider(theme_provider
.Pass());
81 BrowserDesktopWindowTreeHostX11::~BrowserDesktopWindowTreeHostX11() {
84 ////////////////////////////////////////////////////////////////////////////////
85 // BrowserDesktopWindowTreeHostX11,
86 // BrowserDesktopWindowTreeHost implementation:
88 views::DesktopWindowTreeHost
*
89 BrowserDesktopWindowTreeHostX11::AsDesktopWindowTreeHost() {
93 int BrowserDesktopWindowTreeHostX11::GetMinimizeButtonOffset() const {
97 bool BrowserDesktopWindowTreeHostX11::UsesNativeSystemMenu() const {
101 ////////////////////////////////////////////////////////////////////////////////
102 // BrowserDesktopWindowTreeHostX11,
103 // views::DesktopWindowTreeHostX11 implementation:
105 void BrowserDesktopWindowTreeHostX11::Init(
106 aura::Window
* content_window
,
107 const views::Widget::InitParams
& params
) {
108 views::DesktopWindowTreeHostX11::Init(content_window
, params
);
110 // We have now created our backing X11 window. We now need to (possibly)
111 // alert Unity that there's a menu bar attached to it.
112 global_menu_bar_x11_
.reset(new GlobalMenuBarX11(browser_view_
, this));
115 void BrowserDesktopWindowTreeHostX11::CloseNow() {
116 global_menu_bar_x11_
.reset();
117 DesktopWindowTreeHostX11::CloseNow();
120 ////////////////////////////////////////////////////////////////////////////////
121 // BrowserDesktopWindowTreeHost, public:
124 BrowserDesktopWindowTreeHost
*
125 BrowserDesktopWindowTreeHost::CreateBrowserDesktopWindowTreeHost(
126 views::internal::NativeWidgetDelegate
* native_widget_delegate
,
127 views::DesktopNativeWidgetAura
* desktop_native_widget_aura
,
128 BrowserView
* browser_view
,
129 BrowserFrame
* browser_frame
) {
130 return new BrowserDesktopWindowTreeHostX11(native_widget_delegate
,
131 desktop_native_widget_aura
,