| 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 "views/window/native_window_gtk.h" | 5 #include "views/window/native_window_gtk.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "ui/gfx/gtk_util.h" | 9 #include "ui/gfx/gtk_util.h" |
| 10 #include "ui/gfx/path.h" | 10 #include "ui/gfx/path.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 return GDK_LEFT_PTR; | 73 return GDK_LEFT_PTR; |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace | 76 } // namespace |
| 77 | 77 |
| 78 namespace views { | 78 namespace views { |
| 79 | 79 |
| 80 NativeWindowGtk::NativeWindowGtk(internal::NativeWindowDelegate* delegate) | 80 NativeWindowGtk::NativeWindowGtk(internal::NativeWindowDelegate* delegate) |
| 81 : NativeWidgetGtk(delegate->AsNativeWidgetDelegate()), | 81 : NativeWidgetGtk(delegate->AsNativeWidgetDelegate()), |
| 82 delegate_(delegate), | 82 delegate_(delegate), |
| 83 window_state_(GDK_WINDOW_STATE_WITHDRAWN), | |
| 84 window_closed_(false) { | 83 window_closed_(false) { |
| 85 is_window_ = true; | 84 is_window_ = true; |
| 86 } | 85 } |
| 87 | 86 |
| 88 NativeWindowGtk::~NativeWindowGtk() { | 87 NativeWindowGtk::~NativeWindowGtk() { |
| 89 } | 88 } |
| 90 | 89 |
| 91 //////////////////////////////////////////////////////////////////////////////// | 90 //////////////////////////////////////////////////////////////////////////////// |
| 92 // NativeWindowGtk, NativeWidgetGtk overrides: | 91 // NativeWindowGtk, NativeWidgetGtk overrides: |
| 93 | 92 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 allocation->height), | 174 allocation->height), |
| 176 &window_mask); | 175 &window_mask); |
| 177 GdkRegion* mask_region = window_mask.CreateNativeRegion(); | 176 GdkRegion* mask_region = window_mask.CreateNativeRegion(); |
| 178 gdk_window_shape_combine_region(GetNativeView()->window, mask_region, 0, 0); | 177 gdk_window_shape_combine_region(GetNativeView()->window, mask_region, 0, 0); |
| 179 if (mask_region) | 178 if (mask_region) |
| 180 gdk_region_destroy(mask_region); | 179 gdk_region_destroy(mask_region); |
| 181 | 180 |
| 182 SaveWindowPosition(); | 181 SaveWindowPosition(); |
| 183 } | 182 } |
| 184 | 183 |
| 185 gboolean NativeWindowGtk::OnWindowStateEvent(GtkWidget* widget, | |
| 186 GdkEventWindowState* event) { | |
| 187 window_state_ = event->new_window_state; | |
| 188 if (!(window_state_ & GDK_WINDOW_STATE_WITHDRAWN)) | |
| 189 SaveWindowPosition(); | |
| 190 return FALSE; | |
| 191 } | |
| 192 | |
| 193 gboolean NativeWindowGtk::OnLeaveNotify(GtkWidget* widget, | 184 gboolean NativeWindowGtk::OnLeaveNotify(GtkWidget* widget, |
| 194 GdkEventCrossing* event) { | 185 GdkEventCrossing* event) { |
| 195 gdk_window_set_cursor(widget->window, gfx::GetCursor(GDK_LEFT_PTR)); | 186 gdk_window_set_cursor(widget->window, gfx::GetCursor(GDK_LEFT_PTR)); |
| 196 | 187 |
| 197 return NativeWidgetGtk::OnLeaveNotify(widget, event); | 188 return NativeWidgetGtk::OnLeaveNotify(widget, event); |
| 198 } | 189 } |
| 199 | 190 |
| 200 void NativeWindowGtk::IsActiveChanged() { | 191 void NativeWindowGtk::IsActiveChanged() { |
| 201 NativeWidgetGtk::IsActiveChanged(); | 192 NativeWidgetGtk::IsActiveChanged(); |
| 202 delegate_->OnNativeWindowActivationChanged(IsActive()); | 193 delegate_->OnNativeWindowActivationChanged(IsActive()); |
| 203 } | 194 } |
| 204 | 195 |
| 205 void NativeWindowGtk::InitNativeWidget(const Widget::InitParams& params) { | 196 void NativeWindowGtk::InitNativeWidget(const Widget::InitParams& params) { |
| 206 NativeWidgetGtk::InitNativeWidget(params); | 197 NativeWidgetGtk::InitNativeWidget(params); |
| 207 | 198 |
| 208 g_signal_connect(G_OBJECT(GetNativeWindow()), "configure-event", | 199 g_signal_connect(G_OBJECT(GetNativeWindow()), "configure-event", |
| 209 G_CALLBACK(CallConfigureEvent), this); | 200 G_CALLBACK(CallConfigureEvent), this); |
| 210 g_signal_connect(G_OBJECT(GetNativeWindow()), "window-state-event", | |
| 211 G_CALLBACK(CallWindowStateEvent), this); | |
| 212 } | 201 } |
| 213 | 202 |
| 214 //////////////////////////////////////////////////////////////////////////////// | 203 //////////////////////////////////////////////////////////////////////////////// |
| 215 // NativeWindowGtk, NativeWindow implementation: | 204 // NativeWindowGtk, NativeWindow implementation: |
| 216 | 205 |
| 217 NativeWidget* NativeWindowGtk::AsNativeWidget() { | 206 NativeWidget* NativeWindowGtk::AsNativeWidget() { |
| 218 return this; | 207 return this; |
| 219 } | 208 } |
| 220 | 209 |
| 221 const NativeWidget* NativeWindowGtk::AsNativeWidget() const { | 210 const NativeWidget* NativeWindowGtk::AsNativeWidget() const { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 const Window* NativeWindowGtk::GetWindow() const { | 284 const Window* NativeWindowGtk::GetWindow() const { |
| 296 return delegate_->AsWindow(); | 285 return delegate_->AsWindow(); |
| 297 } | 286 } |
| 298 | 287 |
| 299 void NativeWindowGtk::SetWindowBounds(const gfx::Rect& bounds, | 288 void NativeWindowGtk::SetWindowBounds(const gfx::Rect& bounds, |
| 300 gfx::NativeWindow other_window) { | 289 gfx::NativeWindow other_window) { |
| 301 // TODO: need to deal with other_window. | 290 // TODO: need to deal with other_window. |
| 302 NativeWidgetGtk::SetBounds(bounds); | 291 NativeWidgetGtk::SetBounds(bounds); |
| 303 } | 292 } |
| 304 | 293 |
| 305 void NativeWindowGtk::HideWindow() { | |
| 306 GetWindow()->Hide(); | |
| 307 } | |
| 308 | |
| 309 void NativeWindowGtk::Activate() { | |
| 310 gtk_window_present(GTK_WINDOW(GetNativeView())); | |
| 311 } | |
| 312 | |
| 313 void NativeWindowGtk::Deactivate() { | |
| 314 gdk_window_lower(GTK_WIDGET(GetNativeView())->window); | |
| 315 } | |
| 316 | |
| 317 void NativeWindowGtk::Maximize() { | |
| 318 gtk_window_maximize(GetNativeWindow()); | |
| 319 } | |
| 320 | |
| 321 void NativeWindowGtk::Minimize() { | |
| 322 gtk_window_iconify(GetNativeWindow()); | |
| 323 } | |
| 324 | |
| 325 void NativeWindowGtk::Restore() { | |
| 326 if (IsMaximized()) | |
| 327 gtk_window_unmaximize(GetNativeWindow()); | |
| 328 else if (IsMinimized()) | |
| 329 gtk_window_deiconify(GetNativeWindow()); | |
| 330 else if (IsFullscreen()) | |
| 331 SetFullscreen(false); | |
| 332 } | |
| 333 | |
| 334 bool NativeWindowGtk::IsActive() const { | |
| 335 return NativeWidgetGtk::IsActive(); | |
| 336 } | |
| 337 | |
| 338 bool NativeWindowGtk::IsVisible() const { | |
| 339 return GTK_WIDGET_VISIBLE(GetNativeView()); | |
| 340 } | |
| 341 | |
| 342 bool NativeWindowGtk::IsMaximized() const { | |
| 343 return window_state_ & GDK_WINDOW_STATE_MAXIMIZED; | |
| 344 } | |
| 345 | |
| 346 bool NativeWindowGtk::IsMinimized() const { | |
| 347 return window_state_ & GDK_WINDOW_STATE_ICONIFIED; | |
| 348 } | |
| 349 | |
| 350 void NativeWindowGtk::SetFullscreen(bool fullscreen) { | 294 void NativeWindowGtk::SetFullscreen(bool fullscreen) { |
| 351 if (fullscreen) | 295 if (fullscreen) |
| 352 gtk_window_fullscreen(GetNativeWindow()); | 296 gtk_window_fullscreen(GetNativeWindow()); |
| 353 else | 297 else |
| 354 gtk_window_unfullscreen(GetNativeWindow()); | 298 gtk_window_unfullscreen(GetNativeWindow()); |
| 355 } | 299 } |
| 356 | 300 |
| 357 bool NativeWindowGtk::IsFullscreen() const { | 301 bool NativeWindowGtk::IsFullscreen() const { |
| 358 return window_state_ & GDK_WINDOW_STATE_FULLSCREEN; | 302 return window_state_ & GDK_WINDOW_STATE_FULLSCREEN; |
| 359 } | 303 } |
| 360 | 304 |
| 361 void NativeWindowGtk::SetUseDragFrame(bool use_drag_frame) { | 305 void NativeWindowGtk::SetUseDragFrame(bool use_drag_frame) { |
| 362 NOTIMPLEMENTED(); | 306 NOTIMPLEMENTED(); |
| 363 } | 307 } |
| 364 | 308 |
| 365 NonClientFrameView* NativeWindowGtk::CreateFrameViewForWindow() { | 309 NonClientFrameView* NativeWindowGtk::CreateFrameViewForWindow() { |
| 366 return NULL; | 310 return NULL; |
| 367 } | 311 } |
| 368 | 312 |
| 369 void NativeWindowGtk::SetAlwaysOnTop(bool always_on_top) { | |
| 370 gtk_window_set_keep_above(GetNativeWindow(), always_on_top); | |
| 371 } | |
| 372 | |
| 373 void NativeWindowGtk::UpdateFrameAfterFrameChange() { | 313 void NativeWindowGtk::UpdateFrameAfterFrameChange() { |
| 374 // We currently don't support different frame types on Gtk, so we don't | 314 // We currently don't support different frame types on Gtk, so we don't |
| 375 // need to implement this. | 315 // need to implement this. |
| 376 NOTIMPLEMENTED(); | 316 NOTIMPLEMENTED(); |
| 377 } | 317 } |
| 378 | 318 |
| 379 gfx::NativeWindow NativeWindowGtk::GetNativeWindow() const { | |
| 380 return GTK_WINDOW(GetNativeView()); | |
| 381 } | |
| 382 | |
| 383 bool NativeWindowGtk::ShouldUseNativeFrame() const { | 319 bool NativeWindowGtk::ShouldUseNativeFrame() const { |
| 384 return false; | 320 return false; |
| 385 } | 321 } |
| 386 | 322 |
| 387 void NativeWindowGtk::FrameTypeChanged() { | 323 void NativeWindowGtk::FrameTypeChanged() { |
| 388 // This is called when the Theme has changed, so forward the event to the root | 324 // This is called when the Theme has changed, so forward the event to the root |
| 389 // widget. | 325 // widget. |
| 390 GetWidget()->ThemeChanged(); | 326 GetWidget()->ThemeChanged(); |
| 391 GetWidget()->GetRootView()->SchedulePaint(); | 327 GetWidget()->GetRootView()->SchedulePaint(); |
| 392 } | 328 } |
| 393 | 329 |
| 394 //////////////////////////////////////////////////////////////////////////////// | 330 //////////////////////////////////////////////////////////////////////////////// |
| 331 // NativeWindowGtk, NativeWidgetGtk overrides: |
| 332 |
| 333 void NativeWindowGtk::Restore() { |
| 334 if (IsFullscreen()) |
| 335 SetFullscreen(false); |
| 336 else |
| 337 NativeWidgetGtk::Restore(); |
| 338 } |
| 339 |
| 340 gboolean NativeWindowGtk::OnWindowStateEvent(GtkWidget* widget, |
| 341 GdkEventWindowState* event) { |
| 342 if (!(event->new_window_state & GDK_WINDOW_STATE_WITHDRAWN)) |
| 343 SaveWindowPosition(); |
| 344 return NativeWidgetGtk::OnWindowStateEvent(widget, event); |
| 345 } |
| 346 |
| 347 //////////////////////////////////////////////////////////////////////////////// |
| 395 // NativeWindowGtk, private: | 348 // NativeWindowGtk, private: |
| 396 | 349 |
| 397 // static | 350 // static |
| 398 gboolean NativeWindowGtk::CallConfigureEvent(GtkWidget* widget, | 351 gboolean NativeWindowGtk::CallConfigureEvent(GtkWidget* widget, |
| 399 GdkEventConfigure* event, | 352 GdkEventConfigure* event, |
| 400 NativeWindowGtk* window_gtk) { | 353 NativeWindowGtk* window_gtk) { |
| 401 return window_gtk->OnConfigureEvent(widget, event); | 354 return window_gtk->OnConfigureEvent(widget, event); |
| 402 } | 355 } |
| 403 | 356 |
| 404 // static | |
| 405 gboolean NativeWindowGtk::CallWindowStateEvent(GtkWidget* widget, | |
| 406 GdkEventWindowState* event, | |
| 407 NativeWindowGtk* window_gtk) { | |
| 408 return window_gtk->OnWindowStateEvent(widget, event); | |
| 409 } | |
| 410 | |
| 411 void NativeWindowGtk::SaveWindowPosition() { | 357 void NativeWindowGtk::SaveWindowPosition() { |
| 412 // The delegate may have gone away on us. | 358 // The delegate may have gone away on us. |
| 413 if (!GetWindow()->window_delegate()) | 359 if (!GetWindow()->window_delegate()) |
| 414 return; | 360 return; |
| 415 | 361 |
| 416 bool maximized = window_state_ & GDK_WINDOW_STATE_MAXIMIZED; | 362 bool maximized = window_state_ & GDK_WINDOW_STATE_MAXIMIZED; |
| 417 GetWindow()->window_delegate()->SaveWindowPlacement( | 363 GetWindow()->window_delegate()->SaveWindowPlacement( |
| 418 GetWidget()->GetWindowScreenBounds(), | 364 GetWidget()->GetWindowScreenBounds(), |
| 419 maximized); | 365 maximized); |
| 420 } | 366 } |
| 421 | 367 |
| 422 void NativeWindowGtk::OnDestroy(GtkWidget* widget) { | 368 void NativeWindowGtk::OnDestroy(GtkWidget* widget) { |
| 423 delegate_->OnNativeWindowDestroying(); | 369 delegate_->OnNativeWindowDestroying(); |
| 424 NativeWidgetGtk::OnDestroy(widget); | 370 NativeWidgetGtk::OnDestroy(widget); |
| 425 delegate_->OnNativeWindowDestroyed(); | 371 delegate_->OnNativeWindowDestroyed(); |
| 426 } | 372 } |
| 427 | 373 |
| 428 //////////////////////////////////////////////////////////////////////////////// | 374 //////////////////////////////////////////////////////////////////////////////// |
| 429 // NativeWindow, public: | 375 // NativeWindow, public: |
| 430 | 376 |
| 431 // static | 377 // static |
| 432 NativeWindow* NativeWindow::CreateNativeWindow( | 378 NativeWindow* NativeWindow::CreateNativeWindow( |
| 433 internal::NativeWindowDelegate* delegate) { | 379 internal::NativeWindowDelegate* delegate) { |
| 434 return new NativeWindowGtk(delegate); | 380 return new NativeWindowGtk(delegate); |
| 435 } | 381 } |
| 436 | 382 |
| 437 } // namespace views | 383 } // namespace views |
| 438 | 384 |
| OLD | NEW |