| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/controls/native/native_view_host.h" | 5 #include "views/controls/native/native_view_host.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "app/gfx/canvas.h" | 8 #include "app/gfx/canvas.h" |
| 9 #include "views/controls/native/native_view_host_wrapper.h" | 9 #include "views/controls/native/native_view_host_wrapper.h" |
| 10 #include "views/widget/widget.h" | 10 #include "views/widget/widget.h" |
| 11 | 11 |
| 12 namespace views { | 12 namespace views { |
| 13 | 13 |
| 14 // static | 14 // static |
| 15 const char NativeViewHost::kViewClassName[] = "views/NativeViewHost"; | 15 const char NativeViewHost::kViewClassName[] = "views/NativeViewHost"; |
| 16 | 16 |
| 17 //////////////////////////////////////////////////////////////////////////////// | 17 //////////////////////////////////////////////////////////////////////////////// |
| 18 // NativeViewHost, public: | 18 // NativeViewHost, public: |
| 19 | 19 |
| 20 NativeViewHost::NativeViewHost() | 20 NativeViewHost::NativeViewHost() |
| 21 : native_view_(NULL), | 21 : native_view_(NULL), |
| 22 native_wrapper_(NULL), | |
| 23 fast_resize_(false), | 22 fast_resize_(false), |
| 24 focus_view_(NULL) { | 23 focus_view_(NULL) { |
| 25 // The native widget is placed relative to the root. As such, we need to | 24 // The native widget is placed relative to the root. As such, we need to |
| 26 // know when the position of any ancestor changes, or our visibility relative | 25 // know when the position of any ancestor changes, or our visibility relative |
| 27 // to other views changed as it'll effect our position relative to the root. | 26 // to other views changed as it'll effect our position relative to the root. |
| 28 SetNotifyWhenVisibleBoundsInRootChanges(true); | 27 SetNotifyWhenVisibleBoundsInRootChanges(true); |
| 29 } | 28 } |
| 30 | 29 |
| 31 NativeViewHost::~NativeViewHost() { | 30 NativeViewHost::~NativeViewHost() { |
| 32 } | 31 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 55 } | 54 } |
| 56 | 55 |
| 57 //////////////////////////////////////////////////////////////////////////////// | 56 //////////////////////////////////////////////////////////////////////////////// |
| 58 // NativeViewHost, View overrides: | 57 // NativeViewHost, View overrides: |
| 59 | 58 |
| 60 gfx::Size NativeViewHost::GetPreferredSize() { | 59 gfx::Size NativeViewHost::GetPreferredSize() { |
| 61 return preferred_size_; | 60 return preferred_size_; |
| 62 } | 61 } |
| 63 | 62 |
| 64 void NativeViewHost::Layout() { | 63 void NativeViewHost::Layout() { |
| 65 if (!native_view_ || !native_wrapper_) | 64 if (!native_view_ || !native_wrapper_.get()) |
| 66 return; | 65 return; |
| 67 | 66 |
| 68 // Since widgets know nothing about the View hierarchy (they are direct | 67 // Since widgets know nothing about the View hierarchy (they are direct |
| 69 // children of the Widget that hosts our View hierarchy) they need to be | 68 // children of the Widget that hosts our View hierarchy) they need to be |
| 70 // positioned in the coordinate system of the Widget, not the current | 69 // positioned in the coordinate system of the Widget, not the current |
| 71 // view. | 70 // view. |
| 72 gfx::Point top_left; | 71 gfx::Point top_left; |
| 73 ConvertPointToWidget(this, &top_left); | 72 ConvertPointToWidget(this, &top_left); |
| 74 | 73 |
| 75 gfx::Rect vis_bounds = GetVisibleBounds(); | 74 gfx::Rect vis_bounds = GetVisibleBounds(); |
| 76 bool visible = !vis_bounds.IsEmpty(); | 75 bool visible = !vis_bounds.IsEmpty(); |
| 77 | 76 |
| 78 if (visible && !fast_resize_ && native_wrapper_) { | 77 if (visible && !fast_resize_) { |
| 79 if (vis_bounds.size() != size()) { | 78 if (vis_bounds.size() != size()) { |
| 80 // Only a portion of the Widget is really visible. | 79 // Only a portion of the Widget is really visible. |
| 81 int x = vis_bounds.x(); | 80 int x = vis_bounds.x(); |
| 82 int y = vis_bounds.y(); | 81 int y = vis_bounds.y(); |
| 83 native_wrapper_->InstallClip(x, y, vis_bounds.width(), | 82 native_wrapper_->InstallClip(x, y, vis_bounds.width(), |
| 84 vis_bounds.height()); | 83 vis_bounds.height()); |
| 85 } else if (native_wrapper_->HasInstalledClip()) { | 84 } else if (native_wrapper_->HasInstalledClip()) { |
| 86 // The whole widget is visible but we installed a clip on the widget, | 85 // The whole widget is visible but we installed a clip on the widget, |
| 87 // uninstall it. | 86 // uninstall it. |
| 88 native_wrapper_->UninstallClip(); | 87 native_wrapper_->UninstallClip(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 111 Layout(); | 110 Layout(); |
| 112 } | 111 } |
| 113 | 112 |
| 114 void NativeViewHost::VisibleBoundsInRootChanged() { | 113 void NativeViewHost::VisibleBoundsInRootChanged() { |
| 115 Layout(); | 114 Layout(); |
| 116 } | 115 } |
| 117 | 116 |
| 118 void NativeViewHost::ViewHierarchyChanged(bool is_add, View* parent, | 117 void NativeViewHost::ViewHierarchyChanged(bool is_add, View* parent, |
| 119 View* child) { | 118 View* child) { |
| 120 if (is_add && GetWidget()) { | 119 if (is_add && GetWidget()) { |
| 121 if (!native_wrapper_) | 120 if (!native_wrapper_.get()) |
| 122 native_wrapper_ = NativeViewHostWrapper::CreateWrapper(this); | 121 native_wrapper_.reset(NativeViewHostWrapper::CreateWrapper(this)); |
| 123 native_wrapper_->AddedToWidget(); | 122 native_wrapper_->AddedToWidget(); |
| 124 } else if (!is_add) { | 123 } else if (!is_add) { |
| 125 native_wrapper_->RemovedFromWidget(); | 124 native_wrapper_->RemovedFromWidget(); |
| 126 } | 125 } |
| 127 } | 126 } |
| 128 | 127 |
| 129 std::string NativeViewHost::GetClassName() const { | 128 std::string NativeViewHost::GetClassName() const { |
| 130 return kViewClassName; | 129 return kViewClassName; |
| 131 } | 130 } |
| 132 | 131 |
| 133 void NativeViewHost::Focus() { | 132 void NativeViewHost::Focus() { |
| 134 native_wrapper_->SetFocus(); | 133 native_wrapper_->SetFocus(); |
| 135 } | 134 } |
| 136 | 135 |
| 137 } // namespace views | 136 } // namespace views |
| OLD | NEW |