| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ui/views/widget/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "third_party/skia/include/core/SkRegion.h" | 9 #include "third_party/skia/include/core/SkRegion.h" |
| 10 #include "ui/aura/client/activation_change_observer.h" | 10 #include "ui/aura/client/activation_change_observer.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) | 142 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) |
| 143 : delegate_(delegate), | 143 : delegate_(delegate), |
| 144 ALLOW_THIS_IN_INITIALIZER_LIST(desktop_helper_( | 144 ALLOW_THIS_IN_INITIALIZER_LIST(desktop_helper_( |
| 145 ViewsDelegate::views_delegate ? | 145 ViewsDelegate::views_delegate ? |
| 146 ViewsDelegate::views_delegate->CreateNativeWidgetHelper(this) : | 146 ViewsDelegate::views_delegate->CreateNativeWidgetHelper(this) : |
| 147 NULL)), | 147 NULL)), |
| 148 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), | 148 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), |
| 149 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 149 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
| 150 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | 150 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), |
| 151 can_activate_(true), | 151 can_activate_(true), |
| 152 destroying_(false), |
| 152 cursor_(gfx::kNullCursor), | 153 cursor_(gfx::kNullCursor), |
| 153 saved_window_state_(ui::SHOW_STATE_DEFAULT) { | 154 saved_window_state_(ui::SHOW_STATE_DEFAULT) { |
| 154 } | 155 } |
| 155 | 156 |
| 156 // static | 157 // static |
| 157 gfx::Font NativeWidgetAura::GetWindowTitleFont() { | 158 gfx::Font NativeWidgetAura::GetWindowTitleFont() { |
| 158 #if defined(OS_WIN) | 159 #if defined(OS_WIN) |
| 159 NONCLIENTMETRICS ncm; | 160 NONCLIENTMETRICS ncm; |
| 160 base::win::GetNonClientMetrics(&ncm); | 161 base::win::GetNonClientMetrics(&ncm); |
| 161 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); | 162 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 } | 694 } |
| 694 | 695 |
| 695 void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds, | 696 void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds, |
| 696 const gfx::Rect& new_bounds) { | 697 const gfx::Rect& new_bounds) { |
| 697 if (old_bounds.origin() != new_bounds.origin()) | 698 if (old_bounds.origin() != new_bounds.origin()) |
| 698 delegate_->OnNativeWidgetMove(); | 699 delegate_->OnNativeWidgetMove(); |
| 699 if (old_bounds.size() != new_bounds.size()) | 700 if (old_bounds.size() != new_bounds.size()) |
| 700 delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); | 701 delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); |
| 701 } | 702 } |
| 702 | 703 |
| 703 void NativeWidgetAura::OnFocus() { | 704 void NativeWidgetAura::OnFocus(aura::Window* old_focused_window) { |
| 704 // In aura, it is possible for child native widgets to take input and focus, | 705 // In aura, it is possible for child native widgets to take input and focus, |
| 705 // this differs from the behavior on windows. | 706 // this differs from the behavior on windows. |
| 706 GetWidget()->GetInputMethod()->OnFocus(); | 707 GetWidget()->GetInputMethod()->OnFocus(); |
| 707 delegate_->OnNativeFocus(window_); | 708 delegate_->OnNativeFocus(old_focused_window); |
| 708 } | 709 } |
| 709 | 710 |
| 710 void NativeWidgetAura::OnBlur() { | 711 void NativeWidgetAura::OnBlur() { |
| 711 // Not only top level native widget can take input and focus, child | 712 // GetInputMethod() recreates the input method if it's previously been |
| 712 // widgets are allowed also. | 713 // destroyed. If we get called during destruction, the input method will be |
| 713 GetWidget()->GetInputMethod()->OnBlur(); | 714 // gone, and creating a new one and telling it that we lost the focus will |
| 715 // trigger a DCHECK (the new input method doesn't think that we have the focus |
| 716 // and doesn't expect a blur). OnBlur() shouldn't be called during |
| 717 // destruction unless WIDGET_OWNS_NATIVE_WIDGET is set (which is just the case |
| 718 // in tests). |
| 719 if (!destroying_) |
| 720 GetWidget()->GetInputMethod()->OnBlur(); |
| 721 else |
| 722 DCHECK_EQ(ownership_, Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); |
| 723 |
| 714 delegate_->OnNativeBlur(window_->GetFocusManager()->GetFocusedWindow()); | 724 delegate_->OnNativeBlur(window_->GetFocusManager()->GetFocusedWindow()); |
| 715 } | 725 } |
| 716 | 726 |
| 717 bool NativeWidgetAura::OnKeyEvent(aura::KeyEvent* event) { | 727 bool NativeWidgetAura::OnKeyEvent(aura::KeyEvent* event) { |
| 718 if (event->is_char()) { | 728 if (event->is_char()) { |
| 719 // If a ui::InputMethod object is attached to the root window, character | 729 // If a ui::InputMethod object is attached to the root window, character |
| 720 // events are handled inside the object and are not passed to this function. | 730 // events are handled inside the object and are not passed to this function. |
| 721 // If such object is not attached, character events might be sent (e.g. on | 731 // If such object is not attached, character events might be sent (e.g. on |
| 722 // Windows). In this case, we just skip these. | 732 // Windows). In this case, we just skip these. |
| 723 return false; | 733 return false; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 int NativeWidgetAura::OnPerformDrop(const aura::DropTargetEvent& event) { | 905 int NativeWidgetAura::OnPerformDrop(const aura::DropTargetEvent& event) { |
| 896 DCHECK(drop_helper_.get() != NULL); | 906 DCHECK(drop_helper_.get() != NULL); |
| 897 return drop_helper_->OnDrop(event.data(), event.location(), | 907 return drop_helper_->OnDrop(event.data(), event.location(), |
| 898 last_drop_operation_); | 908 last_drop_operation_); |
| 899 } | 909 } |
| 900 | 910 |
| 901 //////////////////////////////////////////////////////////////////////////////// | 911 //////////////////////////////////////////////////////////////////////////////// |
| 902 // NativeWidgetAura, protected: | 912 // NativeWidgetAura, protected: |
| 903 | 913 |
| 904 NativeWidgetAura::~NativeWidgetAura() { | 914 NativeWidgetAura::~NativeWidgetAura() { |
| 915 destroying_ = true; |
| 905 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 916 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
| 906 delete delegate_; | 917 delete delegate_; |
| 907 else | 918 else |
| 908 CloseNow(); | 919 CloseNow(); |
| 909 } | 920 } |
| 910 | 921 |
| 911 //////////////////////////////////////////////////////////////////////////////// | 922 //////////////////////////////////////////////////////////////////////////////// |
| 912 // NativeWidgetAura, private: | 923 // NativeWidgetAura, private: |
| 913 | 924 |
| 914 void NativeWidgetAura::SetInitialFocus() { | 925 void NativeWidgetAura::SetInitialFocus() { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1027 return aura::Env::GetInstance()->is_mouse_button_down(); | 1038 return aura::Env::GetInstance()->is_mouse_button_down(); |
| 1028 } | 1039 } |
| 1029 | 1040 |
| 1030 // static | 1041 // static |
| 1031 bool NativeWidgetPrivate::IsTouchDown() { | 1042 bool NativeWidgetPrivate::IsTouchDown() { |
| 1032 return aura::Env::GetInstance()->is_touch_down(); | 1043 return aura::Env::GetInstance()->is_touch_down(); |
| 1033 } | 1044 } |
| 1034 | 1045 |
| 1035 } // namespace internal | 1046 } // namespace internal |
| 1036 } // namespace views | 1047 } // namespace views |
| OLD | NEW |