| 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/controls/native/native_view_host.h" | 5 #include "ui/views/controls/native/native_view_host.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/gfx/canvas.h" | 8 #include "ui/gfx/canvas.h" |
| 9 #include "ui/views/accessibility/native_view_accessibility.h" | 9 #include "ui/views/accessibility/native_view_accessibility.h" |
| 10 #include "ui/views/controls/native/native_view_host_wrapper.h" | 10 #include "ui/views/controls/native/native_view_host_wrapper.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 const bool NativeViewHost::kRenderNativeControlFocus = true; | 26 const bool NativeViewHost::kRenderNativeControlFocus = true; |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
| 30 // NativeViewHost, public: | 30 // NativeViewHost, public: |
| 31 | 31 |
| 32 NativeViewHost::NativeViewHost() | 32 NativeViewHost::NativeViewHost() |
| 33 : native_view_(NULL), | 33 : native_view_(NULL), |
| 34 fast_resize_(false), | 34 fast_resize_(false), |
| 35 fast_resize_at_last_layout_(false), | 35 fast_resize_at_last_layout_(false), |
| 36 fast_resize_gravity_(GRAVITY_NORTHWEST), |
| 36 focus_view_(NULL) { | 37 focus_view_(NULL) { |
| 37 } | 38 } |
| 38 | 39 |
| 39 NativeViewHost::~NativeViewHost() { | 40 NativeViewHost::~NativeViewHost() { |
| 40 } | 41 } |
| 41 | 42 |
| 42 void NativeViewHost::Attach(gfx::NativeView native_view) { | 43 void NativeViewHost::Attach(gfx::NativeView native_view) { |
| 43 DCHECK(native_view); | 44 DCHECK(native_view); |
| 44 DCHECK(!native_view_); | 45 DCHECK(!native_view_); |
| 45 native_view_ = native_view; | 46 native_view_ = native_view; |
| 46 // If set_focus_view() has not been invoked, this view is the one that should | 47 // If set_focus_view() has not been invoked, this view is the one that should |
| 47 // be seen as focused when the native view receives focus. | 48 // be seen as focused when the native view receives focus. |
| 48 if (!focus_view_) | 49 if (!focus_view_) |
| 49 focus_view_ = this; | 50 focus_view_ = this; |
| 50 native_wrapper_->NativeViewWillAttach(); | 51 native_wrapper_->AttachNativeView(); |
| 51 Widget::ReparentNativeView(native_view_, GetWidget()->GetNativeView()); | |
| 52 Layout(); | |
| 53 | |
| 54 Widget* widget = Widget::GetWidgetForNativeView(native_view); | |
| 55 if (widget) | |
| 56 widget->SetNativeWindowProperty(kWidgetNativeViewHostKey, this); | |
| 57 } | 52 } |
| 58 | 53 |
| 59 void NativeViewHost::Detach() { | 54 void NativeViewHost::Detach() { |
| 60 Detach(false); | 55 Detach(false); |
| 61 } | 56 } |
| 62 | 57 |
| 63 void NativeViewHost::SetPreferredSize(const gfx::Size& size) { | 58 void NativeViewHost::SetPreferredSize(const gfx::Size& size) { |
| 64 preferred_size_ = size; | 59 preferred_size_ = size; |
| 65 PreferredSizeChanged(); | 60 PreferredSizeChanged(); |
| 66 } | 61 } |
| 67 | 62 |
| 63 float NativeViewHost::GetWidthScaleFactor() const { |
| 64 switch (fast_resize_gravity_) { |
| 65 case GRAVITY_NORTHWEST: |
| 66 return 0.0; |
| 67 case GRAVITY_NORTH: |
| 68 return 0.5; |
| 69 case GRAVITY_NORTHEAST: |
| 70 return 1.0; |
| 71 case GRAVITY_EAST: |
| 72 return 1.0; |
| 73 case GRAVITY_SOUTHEAST: |
| 74 return 1.0; |
| 75 case GRAVITY_SOUTH: |
| 76 return 0.5; |
| 77 case GRAVITY_SOUTHWEST: |
| 78 return 0.0; |
| 79 case GRAVITY_WEST: |
| 80 return 0.0; |
| 81 case GRAVITY_CENTER: |
| 82 return 0.5; |
| 83 } |
| 84 NOTREACHED(); |
| 85 return 0.0; |
| 86 } |
| 87 |
| 88 float NativeViewHost::GetHeightScaleFactor() const { |
| 89 switch (fast_resize_gravity_) { |
| 90 case GRAVITY_NORTHWEST: |
| 91 return 0.0; |
| 92 case GRAVITY_NORTH: |
| 93 return 0.0; |
| 94 case GRAVITY_NORTHEAST: |
| 95 return 0.0; |
| 96 case GRAVITY_EAST: |
| 97 return 0.5; |
| 98 case GRAVITY_SOUTHEAST: |
| 99 return 1.0; |
| 100 case GRAVITY_SOUTH: |
| 101 return 1.0; |
| 102 case GRAVITY_SOUTHWEST: |
| 103 return 1.0; |
| 104 case GRAVITY_WEST: |
| 105 return 0.5; |
| 106 case GRAVITY_CENTER: |
| 107 return 0.5; |
| 108 } |
| 109 NOTREACHED(); |
| 110 return 0.0; |
| 111 } |
| 112 |
| 68 void NativeViewHost::NativeViewDestroyed() { | 113 void NativeViewHost::NativeViewDestroyed() { |
| 69 // Detach so we can clear our state and notify the native_wrapper_ to release | 114 // Detach so we can clear our state and notify the native_wrapper_ to release |
| 70 // ref on the native view. | 115 // ref on the native view. |
| 71 Detach(true); | 116 Detach(true); |
| 72 } | 117 } |
| 73 | 118 |
| 74 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
| 75 // NativeViewHost, View overrides: | 120 // NativeViewHost, View overrides: |
| 76 | 121 |
| 77 gfx::Size NativeViewHost::GetPreferredSize() { | 122 gfx::Size NativeViewHost::GetPreferredSize() { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 Widget::GetAllChildWidgets(native_view(), &widgets); | 266 Widget::GetAllChildWidgets(native_view(), &widgets); |
| 222 for (Widget::Widgets::iterator i = widgets.begin(); i != widgets.end(); ++i) { | 267 for (Widget::Widgets::iterator i = widgets.begin(); i != widgets.end(); ++i) { |
| 223 focus_manager->ViewRemoved((*i)->GetRootView()); | 268 focus_manager->ViewRemoved((*i)->GetRootView()); |
| 224 if (!focus_manager->GetFocusedView()) | 269 if (!focus_manager->GetFocusedView()) |
| 225 return; | 270 return; |
| 226 } | 271 } |
| 227 } | 272 } |
| 228 | 273 |
| 229 | 274 |
| 230 } // namespace views | 275 } // namespace views |
| OLD | NEW |