Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / browser_desktop_window_tree_host_x11.cc
blob3a82a73130db904610b5960ff75b1e18069dd215
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"
13 namespace {
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 {
22 public:
23 explicit DesktopThemeProvider(ThemeService* delegate)
24 : delegate_(delegate) {
27 bool UsingSystemTheme() const override {
28 return delegate_->UsingSystemTheme();
30 gfx::ImageSkia* GetImageSkiaNamed(int id) const override {
31 if (delegate_->UsingSystemTheme() && delegate_->HasCustomImage(id))
32 return delegate_->GetImageSkiaNamed(id);
34 return delegate_->GetImageSkiaNamed(
35 chrome::MapThemeImage(chrome::HOST_DESKTOP_TYPE_NATIVE, id));
37 SkColor GetColor(int id) const override { return delegate_->GetColor(id); }
38 int GetDisplayProperty(int id) const override {
39 return delegate_->GetDisplayProperty(id);
41 bool ShouldUseNativeFrame() const override {
42 return delegate_->ShouldUseNativeFrame();
44 bool HasCustomImage(int id) const override {
45 return delegate_->HasCustomImage(
46 chrome::MapThemeImage(chrome::HOST_DESKTOP_TYPE_NATIVE, id));
48 base::RefCountedMemory* GetRawData(int id, ui::ScaleFactor scale_factor)
49 const override {
50 return delegate_->GetRawData(id, scale_factor);
53 private:
54 ThemeService* delegate_;
56 DISALLOW_COPY_AND_ASSIGN(DesktopThemeProvider);
59 } // namespace
61 ////////////////////////////////////////////////////////////////////////////////
62 // BrowserDesktopWindowTreeHostX11, public:
64 BrowserDesktopWindowTreeHostX11::BrowserDesktopWindowTreeHostX11(
65 views::internal::NativeWidgetDelegate* native_widget_delegate,
66 views::DesktopNativeWidgetAura* desktop_native_widget_aura,
67 BrowserView* browser_view,
68 BrowserFrame* browser_frame)
69 : DesktopWindowTreeHostX11(native_widget_delegate,
70 desktop_native_widget_aura),
71 browser_view_(browser_view) {
72 scoped_ptr<ui::ThemeProvider> theme_provider(
73 new DesktopThemeProvider(ThemeServiceFactory::GetForProfile(
74 browser_view->browser()->profile())));
75 browser_frame->SetThemeProvider(theme_provider.Pass());
76 browser_frame->set_frame_type(
77 browser_frame->UseCustomFrame() ? views::Widget::FRAME_TYPE_FORCE_CUSTOM
78 : views::Widget::FRAME_TYPE_FORCE_NATIVE);
81 BrowserDesktopWindowTreeHostX11::~BrowserDesktopWindowTreeHostX11() {
84 ////////////////////////////////////////////////////////////////////////////////
85 // BrowserDesktopWindowTreeHostX11,
86 // BrowserDesktopWindowTreeHost implementation:
88 views::DesktopWindowTreeHost*
89 BrowserDesktopWindowTreeHostX11::AsDesktopWindowTreeHost() {
90 return this;
93 int BrowserDesktopWindowTreeHostX11::GetMinimizeButtonOffset() const {
94 return 0;
97 bool BrowserDesktopWindowTreeHostX11::UsesNativeSystemMenu() const {
98 return false;
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:
123 // static
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,
132 browser_view,
133 browser_frame);