| 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/strings/string_util.h" | 8 #include "base/strings/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/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } // namespace | 69 } // namespace |
| 70 | 70 |
| 71 //////////////////////////////////////////////////////////////////////////////// | 71 //////////////////////////////////////////////////////////////////////////////// |
| 72 // NativeWidgetAura, public: | 72 // NativeWidgetAura, public: |
| 73 | 73 |
| 74 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) | 74 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) |
| 75 : delegate_(delegate), | 75 : delegate_(delegate), |
| 76 window_(new aura::Window(this)), | 76 window_(new aura::Window(this)), |
| 77 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 77 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
| 78 close_widget_factory_(this), | 78 close_widget_factory_(this), |
| 79 can_activate_(true), | |
| 80 destroying_(false), | 79 destroying_(false), |
| 81 cursor_(gfx::kNullCursor), | 80 cursor_(gfx::kNullCursor), |
| 82 saved_window_state_(ui::SHOW_STATE_DEFAULT) { | 81 saved_window_state_(ui::SHOW_STATE_DEFAULT) { |
| 83 aura::client::SetFocusChangeObserver(window_, this); | 82 aura::client::SetFocusChangeObserver(window_, this); |
| 84 aura::client::SetActivationChangeObserver(window_, this); | 83 aura::client::SetActivationChangeObserver(window_, this); |
| 85 } | 84 } |
| 86 | 85 |
| 87 // static | 86 // static |
| 88 void NativeWidgetAura::RegisterNativeWidgetForWindow( | 87 void NativeWidgetAura::RegisterNativeWidgetForWindow( |
| 89 internal::NativeWidgetPrivate* native_widget, | 88 internal::NativeWidgetPrivate* native_widget, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 153 } |
| 155 | 154 |
| 156 // Wait to set the bounds until we have a parent. That way we can know our | 155 // Wait to set the bounds until we have a parent. That way we can know our |
| 157 // true state/bounds (the LayoutManager may enforce a particular | 156 // true state/bounds (the LayoutManager may enforce a particular |
| 158 // state/bounds). | 157 // state/bounds). |
| 159 if (IsMaximized()) | 158 if (IsMaximized()) |
| 160 SetRestoreBounds(window_, window_bounds); | 159 SetRestoreBounds(window_, window_bounds); |
| 161 else | 160 else |
| 162 SetBounds(window_bounds); | 161 SetBounds(window_bounds); |
| 163 window_->set_ignore_events(!params.accept_events); | 162 window_->set_ignore_events(!params.accept_events); |
| 164 can_activate_ = params.can_activate && | |
| 165 params.type != Widget::InitParams::TYPE_CONTROL && | |
| 166 params.type != Widget::InitParams::TYPE_TOOLTIP; | |
| 167 DCHECK(GetWidget()->GetRootView()); | 163 DCHECK(GetWidget()->GetRootView()); |
| 168 if (params.type != Widget::InitParams::TYPE_TOOLTIP) | 164 if (params.type != Widget::InitParams::TYPE_TOOLTIP) |
| 169 tooltip_manager_.reset(new views::TooltipManagerAura(GetWidget())); | 165 tooltip_manager_.reset(new views::TooltipManagerAura(GetWidget())); |
| 170 | 166 |
| 171 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); | 167 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); |
| 172 if (params.type != Widget::InitParams::TYPE_TOOLTIP && | 168 if (params.type != Widget::InitParams::TYPE_TOOLTIP && |
| 173 params.type != Widget::InitParams::TYPE_POPUP) { | 169 params.type != Widget::InitParams::TYPE_POPUP) { |
| 174 aura::client::SetDragDropDelegate(window_, this); | 170 aura::client::SetDragDropDelegate(window_, this); |
| 175 } | 171 } |
| 176 | 172 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED); | 476 ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED); |
| 481 } | 477 } |
| 482 | 478 |
| 483 void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { | 479 void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { |
| 484 if (!window_) | 480 if (!window_) |
| 485 return; | 481 return; |
| 486 | 482 |
| 487 if (state == ui::SHOW_STATE_MAXIMIZED || state == ui::SHOW_STATE_FULLSCREEN) | 483 if (state == ui::SHOW_STATE_MAXIMIZED || state == ui::SHOW_STATE_FULLSCREEN) |
| 488 window_->SetProperty(aura::client::kShowStateKey, state); | 484 window_->SetProperty(aura::client::kShowStateKey, state); |
| 489 window_->Show(); | 485 window_->Show(); |
| 490 if (can_activate_) { | 486 if (delegate_->CanActivate()) { |
| 491 if (state != ui::SHOW_STATE_INACTIVE) | 487 if (state != ui::SHOW_STATE_INACTIVE) |
| 492 Activate(); | 488 Activate(); |
| 493 // SetInitialFocus() should be always be called, even for | 489 // SetInitialFocus() should be always be called, even for |
| 494 // SHOW_STATE_INACTIVE. If the window has to stay inactive, the method will | 490 // SHOW_STATE_INACTIVE. If the window has to stay inactive, the method will |
| 495 // do the right thing. | 491 // do the right thing. |
| 496 SetInitialFocus(state); | 492 SetInitialFocus(state); |
| 497 } | 493 } |
| 498 } | 494 } |
| 499 | 495 |
| 500 bool NativeWidgetAura::IsVisible() const { | 496 bool NativeWidgetAura::IsVisible() const { |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 std::find(window_->layer()->children().begin(), | 762 std::find(window_->layer()->children().begin(), |
| 767 window_->layer()->children().end(), layer)); | 763 window_->layer()->children().end(), layer)); |
| 768 if (root_layer_iter > child_layer_iter) | 764 if (root_layer_iter > child_layer_iter) |
| 769 return false; | 765 return false; |
| 770 } | 766 } |
| 771 } | 767 } |
| 772 return true; | 768 return true; |
| 773 } | 769 } |
| 774 | 770 |
| 775 bool NativeWidgetAura::CanFocus() { | 771 bool NativeWidgetAura::CanFocus() { |
| 776 return can_activate_; | 772 return ShouldActivate(); |
| 777 } | 773 } |
| 778 | 774 |
| 779 void NativeWidgetAura::OnCaptureLost() { | 775 void NativeWidgetAura::OnCaptureLost() { |
| 780 delegate_->OnMouseCaptureLost(); | 776 delegate_->OnMouseCaptureLost(); |
| 781 } | 777 } |
| 782 | 778 |
| 783 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { | 779 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { |
| 784 delegate_->OnNativeWidgetPaint(canvas); | 780 delegate_->OnNativeWidgetPaint(canvas); |
| 785 } | 781 } |
| 786 | 782 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 void NativeWidgetAura::OnGestureEvent(ui::GestureEvent* event) { | 859 void NativeWidgetAura::OnGestureEvent(ui::GestureEvent* event) { |
| 864 DCHECK(window_); | 860 DCHECK(window_); |
| 865 DCHECK(window_->IsVisible() || event->IsEndingEvent()); | 861 DCHECK(window_->IsVisible() || event->IsEndingEvent()); |
| 866 delegate_->OnGestureEvent(event); | 862 delegate_->OnGestureEvent(event); |
| 867 } | 863 } |
| 868 | 864 |
| 869 //////////////////////////////////////////////////////////////////////////////// | 865 //////////////////////////////////////////////////////////////////////////////// |
| 870 // NativeWidgetAura, aura::client::ActivationDelegate implementation: | 866 // NativeWidgetAura, aura::client::ActivationDelegate implementation: |
| 871 | 867 |
| 872 bool NativeWidgetAura::ShouldActivate() const { | 868 bool NativeWidgetAura::ShouldActivate() const { |
| 873 return can_activate_ && delegate_->CanActivate(); | 869 return delegate_->CanActivate(); |
| 874 } | 870 } |
| 875 | 871 |
| 876 //////////////////////////////////////////////////////////////////////////////// | 872 //////////////////////////////////////////////////////////////////////////////// |
| 877 // NativeWidgetAura, aura::client::ActivationChangeObserver implementation: | 873 // NativeWidgetAura, aura::client::ActivationChangeObserver implementation: |
| 878 | 874 |
| 879 void NativeWidgetAura::OnWindowActivated(aura::Window* gained_active, | 875 void NativeWidgetAura::OnWindowActivated(aura::Window* gained_active, |
| 880 aura::Window* lost_active) { | 876 aura::Window* lost_active) { |
| 881 DCHECK(window_ == gained_active || window_ == lost_active); | 877 DCHECK(window_ == gained_active || window_ == lost_active); |
| 882 if (GetWidget()->GetFocusManager()) { | 878 if (GetWidget()->GetFocusManager()) { |
| 883 if (window_ == gained_active) | 879 if (window_ == gained_active) |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); | 1153 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); |
| 1158 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); | 1154 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); |
| 1159 return gfx::FontList(gfx::Font(caption_font)); | 1155 return gfx::FontList(gfx::Font(caption_font)); |
| 1160 #else | 1156 #else |
| 1161 return gfx::FontList(); | 1157 return gfx::FontList(); |
| 1162 #endif | 1158 #endif |
| 1163 } | 1159 } |
| 1164 | 1160 |
| 1165 } // namespace internal | 1161 } // namespace internal |
| 1166 } // namespace views | 1162 } // namespace views |
| OLD | NEW |