| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "views/controls/native_view_host.h" | |
| 6 | |
| 7 #include "views/widget/widget.h" | |
| 8 #include "base/logging.h" | |
| 9 | |
| 10 namespace views { | |
| 11 | |
| 12 NativeViewHost::NativeViewHost() | |
| 13 : native_view_(NULL), | |
| 14 installed_clip_(false), | |
| 15 fast_resize_(false), | |
| 16 focus_view_(NULL) { | |
| 17 // The native widget is placed relative to the root. As such, we need to | |
| 18 // know when the position of any ancestor changes, or our visibility relative | |
| 19 // to other views changed as it'll effect our position relative to the root. | |
| 20 SetNotifyWhenVisibleBoundsInRootChanges(true); | |
| 21 } | |
| 22 | |
| 23 NativeViewHost::~NativeViewHost() { | |
| 24 } | |
| 25 | |
| 26 gfx::Size NativeViewHost::GetPreferredSize() { | |
| 27 return preferred_size_; | |
| 28 } | |
| 29 | |
| 30 void NativeViewHost::SetPreferredSize(const gfx::Size& size) { | |
| 31 preferred_size_ = size; | |
| 32 PreferredSizeChanged(); | |
| 33 } | |
| 34 | |
| 35 void NativeViewHost::Layout() { | |
| 36 if (!native_view_) | |
| 37 return; | |
| 38 | |
| 39 // Since widgets know nothing about the View hierarchy (they are direct | |
| 40 // children of the Widget that hosts our View hierarchy) they need to be | |
| 41 // positioned in the coordinate system of the Widget, not the current | |
| 42 // view. | |
| 43 gfx::Point top_left; | |
| 44 ConvertPointToWidget(this, &top_left); | |
| 45 | |
| 46 gfx::Rect vis_bounds = GetVisibleBounds(); | |
| 47 bool visible = !vis_bounds.IsEmpty(); | |
| 48 | |
| 49 if (visible && !fast_resize_) { | |
| 50 if (vis_bounds.size() != size()) { | |
| 51 // Only a portion of the Widget is really visible. | |
| 52 int x = vis_bounds.x(); | |
| 53 int y = vis_bounds.y(); | |
| 54 InstallClip(x, y, vis_bounds.width(), vis_bounds.height()); | |
| 55 installed_clip_ = true; | |
| 56 } else if (installed_clip_) { | |
| 57 // The whole widget is visible but we installed a clip on the widget, | |
| 58 // uninstall it. | |
| 59 UninstallClip(); | |
| 60 installed_clip_ = false; | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 if (visible) { | |
| 65 ShowWidget(top_left.x(), top_left.y(), width(), height()); | |
| 66 } else { | |
| 67 HideWidget(); | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 void NativeViewHost::VisibilityChanged(View* starting_from, bool is_visible) { | |
| 72 Layout(); | |
| 73 } | |
| 74 | |
| 75 void NativeViewHost::VisibleBoundsInRootChanged() { | |
| 76 Layout(); | |
| 77 } | |
| 78 | |
| 79 } // namespace views | |
| OLD | NEW |