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/widget/native_widget_views.h" | 5 #include "views/widget/native_widget_views.h" |
6 | 6 |
7 #include "ui/gfx/compositor/compositor.h" | 7 #include "ui/gfx/compositor/compositor.h" |
8 #include "views/desktop/desktop_window_view.h" | |
9 #include "views/view.h" | 8 #include "views/view.h" |
10 #include "views/views_delegate.h" | 9 #include "views/views_delegate.h" |
11 #include "views/widget/native_widget_view.h" | 10 #include "views/widget/native_widget_view.h" |
12 #include "views/widget/root_view.h" | 11 #include "views/widget/root_view.h" |
13 #include "views/widget/window_manager.h" | 12 #include "views/widget/window_manager.h" |
14 | 13 |
15 #if defined(HAVE_IBUS) | 14 #if defined(HAVE_IBUS) |
16 #include "views/ime/input_method_ibus.h" | 15 #include "views/ime/input_method_ibus.h" |
17 #else | 16 #else |
18 #include "views/ime/mock_input_method.h" | 17 #include "views/ime/mock_input_method.h" |
19 #endif | 18 #endif |
20 | 19 |
21 #if defined(OS_LINUX) | 20 #if defined(OS_LINUX) |
22 #include "views/window/hit_test.h" | 21 #include "views/window/hit_test.h" |
23 #endif | 22 #endif |
24 | 23 |
25 namespace views { | 24 namespace views { |
26 | 25 |
27 //////////////////////////////////////////////////////////////////////////////// | 26 //////////////////////////////////////////////////////////////////////////////// |
28 // NativeWidgetViews, public: | 27 // NativeWidgetViews, public: |
29 | 28 |
30 NativeWidgetViews::NativeWidgetViews(internal::NativeWidgetDelegate* delegate) | 29 NativeWidgetViews::NativeWidgetViews(internal::NativeWidgetDelegate* delegate) |
31 : delegate_(delegate), | 30 : delegate_(delegate), |
32 view_(NULL), | 31 view_(NULL), |
33 active_(false), | 32 active_(false), |
34 minimized_(false), | 33 window_state_(ui::SHOW_STATE_DEFAULT), |
35 always_on_top_(false), | 34 always_on_top_(false), |
36 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | 35 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), |
37 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 36 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
38 delete_native_view_(true) { | 37 delete_native_view_(true) { |
39 } | 38 } |
40 | 39 |
41 NativeWidgetViews::~NativeWidgetViews() { | 40 NativeWidgetViews::~NativeWidgetViews() { |
42 delegate_->OnNativeWidgetDestroying(); | 41 delegate_->OnNativeWidgetDestroying(); |
43 | 42 |
44 if (view_ && delete_native_view_) { | 43 if (view_ && delete_native_view_) { |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 402 |
404 void NativeWidgetViews::SetAlwaysOnTop(bool on_top) { | 403 void NativeWidgetViews::SetAlwaysOnTop(bool on_top) { |
405 always_on_top_ = on_top; | 404 always_on_top_ = on_top; |
406 // This is not complete yet. At least |MoveToTop| will need to be updated to | 405 // This is not complete yet. At least |MoveToTop| will need to be updated to |
407 // make sure a 'normal' window does not get on top of a window with | 406 // make sure a 'normal' window does not get on top of a window with |
408 // |always_on_top_| set. | 407 // |always_on_top_| set. |
409 NOTIMPLEMENTED(); | 408 NOTIMPLEMENTED(); |
410 } | 409 } |
411 | 410 |
412 void NativeWidgetViews::Maximize() { | 411 void NativeWidgetViews::Maximize() { |
413 NOTIMPLEMENTED(); | 412 if (window_state_ == ui::SHOW_STATE_MAXIMIZED) |
| 413 return; |
| 414 |
| 415 if (window_state_ != ui::SHOW_STATE_MINIMIZED) { |
| 416 // Remember bounds and transform to use when unmaximized. |
| 417 restored_bounds_ = view_->bounds(); |
| 418 restored_transform_ = view_->GetTransform(); |
| 419 } |
| 420 |
| 421 window_state_ = ui::SHOW_STATE_MAXIMIZED; |
| 422 gfx::Size size = GetParentNativeWidget()->GetWindowScreenBounds().size(); |
| 423 SetBounds(gfx::Rect(gfx::Point(), size)); |
414 } | 424 } |
415 | 425 |
416 void NativeWidgetViews::Minimize() { | 426 void NativeWidgetViews::Minimize() { |
417 gfx::Rect view_bounds = view_->bounds(); | 427 gfx::Rect view_bounds = view_->bounds(); |
418 gfx::Rect parent_bounds = view_->parent()->bounds(); | 428 gfx::Rect parent_bounds = view_->parent()->bounds(); |
419 | 429 |
420 restored_bounds_ = view_bounds; | 430 if (window_state_ != ui::SHOW_STATE_MAXIMIZED) { |
421 restored_transform_ = view_->GetTransform(); | 431 restored_bounds_ = view_bounds; |
| 432 restored_transform_ = view_->GetTransform(); |
| 433 } |
422 | 434 |
423 float aspect_ratio = static_cast<float>(view_bounds.width()) / | 435 float aspect_ratio = static_cast<float>(view_bounds.width()) / |
424 static_cast<float>(view_bounds.height()); | 436 static_cast<float>(view_bounds.height()); |
425 int target_size = 100; | 437 int target_size = 100; |
426 int target_height = target_size; | 438 int target_height = target_size; |
427 int target_width = static_cast<int>(aspect_ratio * target_height); | 439 int target_width = static_cast<int>(aspect_ratio * target_height); |
428 if (target_width > target_size) { | 440 if (target_width > target_size) { |
429 target_width = target_size; | 441 target_width = target_size; |
430 target_height = static_cast<int>(target_width / aspect_ratio); | 442 target_height = static_cast<int>(target_width / aspect_ratio); |
431 } | 443 } |
432 | 444 |
433 int target_x = 20; | 445 int target_x = 20; |
434 int target_y = parent_bounds.height() - target_size - 20; | 446 int target_y = parent_bounds.height() - target_size - 20; |
435 | 447 |
436 view_->SetBounds( | 448 view_->SetBounds( |
437 target_x, target_y, view_bounds.width(), view_bounds.height()); | 449 target_x, target_y, view_bounds.width(), view_bounds.height()); |
438 | 450 |
439 ui::Transform transform; | 451 ui::Transform transform; |
440 transform.SetScale((float)target_width / (float)view_bounds.width(), | 452 transform.SetScale((float)target_width / (float)view_bounds.width(), |
441 (float)target_height / (float)view_bounds.height()); | 453 (float)target_height / (float)view_bounds.height()); |
442 view_->SetTransform(transform); | 454 view_->SetTransform(transform); |
443 | 455 |
444 minimized_ = true; | 456 window_state_ = ui::SHOW_STATE_MINIMIZED; |
445 } | 457 } |
446 | 458 |
447 bool NativeWidgetViews::IsMaximized() const { | 459 bool NativeWidgetViews::IsMaximized() const { |
448 // NOTIMPLEMENTED(); | 460 return window_state_ == ui::SHOW_STATE_MAXIMIZED; |
449 return false; | |
450 } | 461 } |
451 | 462 |
452 bool NativeWidgetViews::IsMinimized() const { | 463 bool NativeWidgetViews::IsMinimized() const { |
453 return minimized_; | 464 return window_state_ == ui::SHOW_STATE_MINIMIZED; |
454 } | 465 } |
455 | 466 |
456 void NativeWidgetViews::Restore() { | 467 void NativeWidgetViews::Restore() { |
457 minimized_ = false; | 468 window_state_ = ui::SHOW_STATE_NORMAL; |
458 view_->SetBoundsRect(restored_bounds_); | 469 view_->SetBoundsRect(restored_bounds_); |
459 view_->SetTransform(restored_transform_); | 470 view_->SetTransform(restored_transform_); |
460 } | 471 } |
461 | 472 |
462 void NativeWidgetViews::SetFullscreen(bool fullscreen) { | 473 void NativeWidgetViews::SetFullscreen(bool fullscreen) { |
463 NOTIMPLEMENTED(); | 474 NOTIMPLEMENTED(); |
464 } | 475 } |
465 | 476 |
466 bool NativeWidgetViews::IsFullscreen() const { | 477 bool NativeWidgetViews::IsFullscreen() const { |
467 // NOTIMPLEMENTED(); | 478 // NOTIMPLEMENTED(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 } | 592 } |
582 default: | 593 default: |
583 // Everything else falls into standard client event handling. | 594 // Everything else falls into standard client event handling. |
584 break; | 595 break; |
585 } | 596 } |
586 } | 597 } |
587 return false; | 598 return false; |
588 } | 599 } |
589 | 600 |
590 } // namespace views | 601 } // namespace views |
OLD | NEW |