OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/frame/bubble_window.h" | 5 #include "chrome/browser/chromeos/frame/bubble_window.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include "chrome/browser/chromeos/frame/bubble_frame_view.h" | 9 #include "chrome/browser/chromeos/frame/bubble_frame_view.h" |
10 #include "chrome/browser/chromeos/wm_ipc.h" | 10 #include "chrome/browser/chromeos/wm_ipc.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 gdk_region_union_with_rect(region, &rect); | 23 gdk_region_union_with_rect(region, &rect); |
24 } | 24 } |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 namespace chromeos { | 28 namespace chromeos { |
29 | 29 |
30 // static | 30 // static |
31 const SkColor BubbleWindow::kBackgroundColor = SK_ColorWHITE; | 31 const SkColor BubbleWindow::kBackgroundColor = SK_ColorWHITE; |
32 | 32 |
33 BubbleWindow::BubbleWindow() { | 33 BubbleWindow::BubbleWindow(views::Window* window) |
| 34 : views::WindowGtk::WindowGtk(window) { |
34 MakeTransparent(); | 35 MakeTransparent(); |
35 } | 36 } |
36 | 37 |
37 void BubbleWindow::InitNativeWidget(const views::Widget::InitParams& params) { | 38 void BubbleWindow::InitNativeWidget(const views::Widget::InitParams& params) { |
38 views::WindowGtk::InitNativeWidget(params); | 39 views::WindowGtk::InitNativeWidget(params); |
39 | 40 |
40 // Turn on double buffering so that the hosted GtkWidgets does not | 41 // Turn on double buffering so that the hosted GtkWidgets does not |
41 // flash as in http://crosbug.com/9065. | 42 // flash as in http://crosbug.com/9065. |
42 EnableDoubleBuffer(true); | 43 EnableDoubleBuffer(true); |
43 | 44 |
44 GdkColor background_color = gfx::SkColorToGdkColor(kBackgroundColor); | 45 GdkColor background_color = gfx::SkColorToGdkColor(kBackgroundColor); |
45 gtk_widget_modify_bg(GetNativeView(), GTK_STATE_NORMAL, &background_color); | 46 gtk_widget_modify_bg(GetNativeView(), GTK_STATE_NORMAL, &background_color); |
46 | 47 |
47 // A work-around for http://crosbug.com/8538. All GdkWindow of top-level | 48 // A work-around for http://crosbug.com/8538. All GdkWindow of top-level |
48 // GtkWindow should participate _NET_WM_SYNC_REQUEST protocol and window | 49 // GtkWindow should participate _NET_WM_SYNC_REQUEST protocol and window |
49 // manager should only show the window after getting notified. And we | 50 // manager should only show the window after getting notified. And we |
50 // should only notify window manager after at least one paint is done. | 51 // should only notify window manager after at least one paint is done. |
51 // TODO(xiyuan): Figure out the right fix. | 52 // TODO(xiyuan): Figure out the right fix. |
52 gtk_widget_realize(GetNativeView()); | 53 gtk_widget_realize(GetNativeView()); |
53 gdk_window_set_back_pixmap(GetNativeView()->window, NULL, FALSE); | 54 gdk_window_set_back_pixmap(GetNativeView()->window, NULL, FALSE); |
54 gtk_widget_realize(window_contents()); | 55 gtk_widget_realize(window_contents()); |
55 gdk_window_set_back_pixmap(window_contents()->window, NULL, FALSE); | 56 gdk_window_set_back_pixmap(window_contents()->window, NULL, FALSE); |
56 } | 57 } |
57 | 58 |
58 void BubbleWindow::TrimMargins(int margin_left, int margin_right, | 59 void BubbleWindow::TrimMargins(int margin_left, int margin_right, |
59 int margin_top, int margin_bottom, | 60 int margin_top, int margin_bottom, |
60 int border_radius) { | 61 int border_radius) { |
61 gfx::Size size = non_client_view()->GetPreferredSize(); | 62 gfx::Size size = GetWindow()->non_client_view()->GetPreferredSize(); |
62 const int w = size.width() - margin_left - margin_right; | 63 const int w = size.width() - margin_left - margin_right; |
63 const int h = size.height() - margin_top - margin_bottom; | 64 const int h = size.height() - margin_top - margin_bottom; |
64 GdkRectangle rect0 = {0, border_radius, w, h - 2 * border_radius}; | 65 GdkRectangle rect0 = {0, border_radius, w, h - 2 * border_radius}; |
65 GdkRectangle rect1 = {border_radius, 0, w - 2 * border_radius, h}; | 66 GdkRectangle rect1 = {border_radius, 0, w - 2 * border_radius, h}; |
66 GdkRegion* region = gdk_region_rectangle(&rect0); | 67 GdkRegion* region = gdk_region_rectangle(&rect0); |
67 gdk_region_union_with_rect(region, &rect1); | 68 gdk_region_union_with_rect(region, &rect1); |
68 | 69 |
69 // Top Left | 70 // Top Left |
70 for (int i = 0; i < border_radius; ++i) { | 71 for (int i = 0; i < border_radius; ++i) { |
71 for (int j = 0; j < border_radius; ++j) { | 72 for (int j = 0; j < border_radius; ++j) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 gdk_window_shape_combine_region(window_contents()->window, region, | 107 gdk_window_shape_combine_region(window_contents()->window, region, |
107 margin_left, margin_top); | 108 margin_left, margin_top); |
108 gdk_region_destroy(region); | 109 gdk_region_destroy(region); |
109 } | 110 } |
110 | 111 |
111 views::Window* BubbleWindow::Create( | 112 views::Window* BubbleWindow::Create( |
112 gfx::NativeWindow parent, | 113 gfx::NativeWindow parent, |
113 const gfx::Rect& bounds, | 114 const gfx::Rect& bounds, |
114 Style style, | 115 Style style, |
115 views::WindowDelegate* window_delegate) { | 116 views::WindowDelegate* window_delegate) { |
116 views::Window* window = new BubbleWindow(); | 117 views::Window* window = new views::Window; |
| 118 BubbleWindow* bubble_window = new BubbleWindow(window); |
117 window->non_client_view()->SetFrameView( | 119 window->non_client_view()->SetFrameView( |
118 new BubbleFrameView(window, window_delegate, style)); | 120 new BubbleFrameView(window, window_delegate, style)); |
119 views::Window::InitParams params(window_delegate); | 121 views::Window::InitParams params(window_delegate); |
120 params.parent_window = parent; | 122 params.parent_window = parent; |
| 123 params.native_window = bubble_window; |
121 params.widget_init_params.parent = GTK_WIDGET(parent); | 124 params.widget_init_params.parent = GTK_WIDGET(parent); |
122 params.widget_init_params.bounds = bounds; | 125 params.widget_init_params.bounds = bounds; |
123 params.widget_init_params.parent = GTK_WIDGET(parent); | 126 params.widget_init_params.parent = GTK_WIDGET(parent); |
| 127 params.widget_init_params.native_widget = bubble_window; |
124 window->InitWindow(params); | 128 window->InitWindow(params); |
125 | 129 |
126 if (style == STYLE_XSHAPE) { | 130 if (style == STYLE_XSHAPE) { |
127 const int kMarginLeft = 14; | 131 const int kMarginLeft = 14; |
128 const int kMarginRight = 14; | 132 const int kMarginRight = 14; |
129 const int kMarginTop = 12; | 133 const int kMarginTop = 12; |
130 const int kMarginBottom = 16; | 134 const int kMarginBottom = 16; |
131 const int kBorderRadius = 8; | 135 const int kBorderRadius = 8; |
132 static_cast<BubbleWindow*>(window->native_window())-> | 136 static_cast<BubbleWindow*>(window->native_window())-> |
133 TrimMargins(kMarginLeft, kMarginRight, kMarginTop, kMarginBottom, | 137 TrimMargins(kMarginLeft, kMarginRight, kMarginTop, kMarginBottom, |
134 kBorderRadius); | 138 kBorderRadius); |
135 } | 139 } |
136 | 140 |
137 return window; | 141 return window; |
138 } | 142 } |
139 | 143 |
140 } // namespace chromeos | 144 } // namespace chromeos |
OLD | NEW |