summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/dom_view.cc
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 00:09:01 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 00:09:01 +0000
commit63938b535e41098cb510ee62cd0e284358ba9618 (patch)
tree161597a63a460484353c12e1a130322fa770ad54 /chrome/browser/views/dom_view.cc
parent4478c651139125df2de939b2085592fd206db97e (diff)
downloadchromium_src-63938b535e41098cb510ee62cd0e284358ba9618.zip
chromium_src-63938b535e41098cb510ee62cd0e284358ba9618.tar.gz
chromium_src-63938b535e41098cb510ee62cd0e284358ba9618.tar.bz2
Fixed attach logic so that DOMView can be initialized before or after added to Widget.
* Attach native view in Init if Widget exists. * Attach native view when the view is added to Widget if it's initialized but not yet attached. Detach native view when it's removed from parent view so that it can be re-attached. BUG=none TEST=none Review URL: http://codereview.chromium.org/3152053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57612 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/dom_view.cc')
-rw-r--r--chrome/browser/views/dom_view.cc15
1 files changed, 14 insertions, 1 deletions
diff --git a/chrome/browser/views/dom_view.cc b/chrome/browser/views/dom_view.cc
index 4725cf9..9c42201 100644
--- a/chrome/browser/views/dom_view.cc
+++ b/chrome/browser/views/dom_view.cc
@@ -23,7 +23,9 @@ bool DOMView::Init(Profile* profile, SiteInstance* instance) {
initialized_ = true;
tab_contents_.reset(CreateTabContents(profile, instance));
- views::NativeViewHost::Attach(tab_contents_->GetNativeView());
+ // Attach the native_view now if the view is already added to Widget.
+ if (GetWidget())
+ Attach(tab_contents_->GetNativeView());
return true;
}
@@ -47,3 +49,14 @@ bool DOMView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) {
void DOMView::Focus() {
tab_contents_->Focus();
}
+
+void DOMView::ViewHierarchyChanged(bool is_add, views::View* parent,
+ views::View* child) {
+ // Attach the native_view when this is added to Widget if
+ // the native view has not been attached yet and tab_contents_ exists.
+ views::NativeViewHost::ViewHierarchyChanged(is_add, parent, child);
+ if (is_add && GetWidget() && !native_view() && tab_contents_.get())
+ Attach(tab_contents_->GetNativeView());
+ else if (!is_add && child == this && native_view())
+ Detach();
+}