Commit 8dc4077b authored by Xiyuan Xia's avatar Xiyuan Xia Committed by Commit Bot

mash: Clean up AnswerCardWebContents deps

Move AppListView::ExcludeWindowFromEventHandling from browser process
to app list code in ash process.

Bug: 854787
Change-Id: I7509fdd8c5cc4ea0db211bdc4c7fe8715fb10660
Reviewed-on: https://chromium-review.googlesource.com/1170036
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583075}
parent 340e51f3
...@@ -258,8 +258,8 @@ class AppListViewFocusTest : public views::ViewsTestBase, ...@@ -258,8 +258,8 @@ class AppListViewFocusTest : public views::ViewsTestBase,
std::make_unique<AnswerCardContentsRegistry>(); std::make_unique<AnswerCardContentsRegistry>();
fake_answer_card_view_ = std::make_unique<views::View>(); fake_answer_card_view_ = std::make_unique<views::View>();
fake_answer_card_view_->set_owned_by_client(); fake_answer_card_view_->set_owned_by_client();
fake_answer_card_token_ = fake_answer_card_token_ = answer_card_contents_registry_->Register(
answer_card_contents_registry_->Register(fake_answer_card_view_.get()); fake_answer_card_view_.get(), /*contents_native_view=*/nullptr);
// Initialize app list view. // Initialize app list view.
delegate_ = std::make_unique<AppListTestViewDelegate>(); delegate_ = std::make_unique<AppListTestViewDelegate>();
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/app_list/app_list_metrics.h" #include "ash/app_list/app_list_metrics.h"
#include "ash/app_list/app_list_view_delegate.h" #include "ash/app_list/app_list_view_delegate.h"
#include "ash/app_list/views/app_list_view.h"
#include "ash/app_list/views/search_result_base_view.h" #include "ash/app_list/views/search_result_base_view.h"
#include "ash/public/cpp/app_list/answer_card_contents_registry.h" #include "ash/public/cpp/app_list/answer_card_contents_registry.h"
#include "ash/public/cpp/app_list/app_list_constants.h" #include "ash/public/cpp/app_list/app_list_constants.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include "services/ui/public/interfaces/window_tree.mojom.h" #include "services/ui/public/interfaces/window_tree.mojom.h"
#include "ui/accessibility/ax_node.h" #include "ui/accessibility/ax_node.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
#include "ui/aura/window.h"
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/views/background.h" #include "ui/views/background.h"
...@@ -56,6 +58,35 @@ views::View* GetViewByToken( ...@@ -56,6 +58,35 @@ views::View* GetViewByToken(
return nullptr; return nullptr;
} }
// If there is a card native view identified by |token| in
// AnswerCardContentsRegistry, exclude it from event handling.
void ExcludeFromEventHandlingByToken(
const base::Optional<base::UnguessableToken>& token) {
if (!AnswerCardContentsRegistry::Get())
return;
DCHECK(token.has_value() && !token->is_empty());
gfx::NativeView card_native_view =
AnswerCardContentsRegistry::Get()->GetNativeView(token.value());
// |card_native_view| could be null in tests.
if (!card_native_view)
return;
// |card_native_view| is brought into View's hierarchy via a NativeViewHost.
// The window hierarchy looks like this:
// widget window -> clipping window -> content_native_view
// Events should be targeted to the widget window and by-passing the sub tree
// started at clipping window. Walking up the window hierarchy to find the
// clipping window and make the cut there.
aura::Window* top_level = card_native_view->GetToplevelWindow();
DCHECK(top_level);
aura::Window* window = card_native_view;
while (window->parent() != top_level)
window = window->parent();
AppListView::ExcludeWindowFromEventHandling(window);
}
} // namespace } // namespace
// Container of the search answer view. // Container of the search answer view.
...@@ -92,8 +123,10 @@ class SearchResultAnswerCardView::SearchAnswerContainerView ...@@ -92,8 +123,10 @@ class SearchResultAnswerCardView::SearchAnswerContainerView
RemoveAllChildViews(true /* delete_children */); RemoveAllChildViews(true /* delete_children */);
result_view = GetViewByToken(new_token); result_view = GetViewByToken(new_token);
if (result_view) if (result_view) {
AddChildView(result_view); AddChildView(result_view);
ExcludeFromEventHandlingByToken(new_token);
}
} }
base::string16 old_title; base::string16 old_title;
......
...@@ -44,7 +44,8 @@ class SearchResultAnswerCardViewTest : public views::ViewsTestBase { ...@@ -44,7 +44,8 @@ class SearchResultAnswerCardViewTest : public views::ViewsTestBase {
result_view_ = std::make_unique<views::View>(); result_view_ = std::make_unique<views::View>();
result_view_->set_owned_by_client(); result_view_->set_owned_by_client();
token_ = contents_registry_.Register(result_view_.get()); token_ = contents_registry_.Register(result_view_.get(),
/*contents_native_view=*/nullptr);
SetUpSearchResult(); SetUpSearchResult();
} }
......
...@@ -30,9 +30,10 @@ AnswerCardContentsRegistry* AnswerCardContentsRegistry::Get() { ...@@ -30,9 +30,10 @@ AnswerCardContentsRegistry* AnswerCardContentsRegistry::Get() {
} }
base::UnguessableToken AnswerCardContentsRegistry::Register( base::UnguessableToken AnswerCardContentsRegistry::Register(
views::View* contents_view) { views::View* contents_view,
gfx::NativeView contents_native_view) {
const base::UnguessableToken token = base::UnguessableToken::Create(); const base::UnguessableToken token = base::UnguessableToken::Create();
contents_map_[token] = contents_view; contents_map_[token] = {contents_view, contents_native_view};
return token; return token;
} }
...@@ -51,7 +52,16 @@ views::View* AnswerCardContentsRegistry::GetView( ...@@ -51,7 +52,16 @@ views::View* AnswerCardContentsRegistry::GetView(
if (it == contents_map_.end()) if (it == contents_map_.end())
return nullptr; return nullptr;
return it->second; return it->second.view;
}
gfx::NativeView AnswerCardContentsRegistry::GetNativeView(
const base::UnguessableToken& token) {
auto it = contents_map_.find(token);
if (it == contents_map_.end())
return nullptr;
return it->second.native_view;
} }
} // namespace app_list } // namespace app_list
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/public/cpp/ash_public_export.h" #include "ash/public/cpp/ash_public_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/unguessable_token.h" #include "base/unguessable_token.h"
#include "ui/gfx/native_widget_types.h"
namespace views { namespace views {
class View; class View;
...@@ -32,17 +33,24 @@ class ASH_PUBLIC_EXPORT AnswerCardContentsRegistry { ...@@ -32,17 +33,24 @@ class ASH_PUBLIC_EXPORT AnswerCardContentsRegistry {
static AnswerCardContentsRegistry* Get(); static AnswerCardContentsRegistry* Get();
// Register content with a View. // Register content with a View and its relevant NativeView.
base::UnguessableToken Register(views::View* contents_view); base::UnguessableToken Register(views::View* contents_view,
gfx::NativeView contents_native_view);
// Unregister and release the associated resources. // Unregister and release the associated resources.
void Unregister(const base::UnguessableToken& token); void Unregister(const base::UnguessableToken& token);
// Get the view for the given token. Return nullptr for unknown token. // Get the view for the given token. Return nullptr for unknown token.
views::View* GetView(const base::UnguessableToken& token); views::View* GetView(const base::UnguessableToken& token);
gfx::NativeView GetNativeView(const base::UnguessableToken& token);
private: private:
std::map<base::UnguessableToken, views::View*> contents_map_; struct Entry {
views::View* view;
gfx::NativeView native_view;
};
std::map<base::UnguessableToken, Entry> contents_map_;
DISALLOW_COPY_AND_ASSIGN(AnswerCardContentsRegistry); DISALLOW_COPY_AND_ASSIGN(AnswerCardContentsRegistry);
}; };
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include <string> #include <string>
#include "ash/app_list/views/app_list_view.h"
#include "ash/public/cpp/app_list/answer_card_contents_registry.h" #include "ash/public/cpp/app_list/answer_card_contents_registry.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
...@@ -69,14 +68,6 @@ class SearchAnswerWebView : public views::WebView { ...@@ -69,14 +68,6 @@ class SearchAnswerWebView : public views::WebView {
void AddedToWidget() override { void AddedToWidget() override {
WebView::AddedToWidget(); WebView::AddedToWidget();
// Find the root element that attached to the app list view.
aura::Window* const app_list_window =
web_contents()->GetTopLevelNativeWindow();
aura::Window* window = web_contents()->GetNativeView();
while (window->parent() != app_list_window)
window = window->parent();
AppListView::ExcludeWindowFromEventHandling(window);
OnVisibilityEvent(false); OnVisibilityEvent(false);
// Focus Behavior is originally set in WebView::SetWebContents, but // Focus Behavior is originally set in WebView::SetWebContents, but
// overriden here because we do not want the webview to get focus. // overriden here because we do not want the webview to get focus.
...@@ -173,7 +164,8 @@ AnswerCardWebContents::AnswerCardWebContents(Profile* profile) ...@@ -173,7 +164,8 @@ AnswerCardWebContents::AnswerCardWebContents(Profile* profile)
web_view_->SetWebContents(web_contents_.get()); web_view_->SetWebContents(web_contents_.get());
web_view_->SetResizeBackgroundColor(SK_ColorTRANSPARENT); web_view_->SetResizeBackgroundColor(SK_ColorTRANSPARENT);
token_ = AnswerCardContentsRegistry::Get()->Register(web_view_.get()); token_ = AnswerCardContentsRegistry::Get()->Register(
web_view_.get(), web_contents_->GetNativeView());
} }
} }
......
...@@ -153,7 +153,7 @@ class ManagedWebContents : public content::WebContentsDelegate, ...@@ -153,7 +153,7 @@ class ManagedWebContents : public content::WebContentsDelegate,
web_view_->SetWebContents(web_contents_.get()); web_view_->SetWebContents(web_contents_.get());
embed_token_ = app_list::AnswerCardContentsRegistry::Get()->Register( embed_token_ = app_list::AnswerCardContentsRegistry::Get()->Register(
web_view_.get()); web_view_.get(), web_contents_->GetNativeView());
} else { } else {
// TODO(dmblack): Handle Mash case. https://crbug.com/854787. // TODO(dmblack): Handle Mash case. https://crbug.com/854787.
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment