Commit 36debc58 authored by apacible's avatar apacible Committed by Commit Bot

[OverlayWindow] Add platform-independent window and views implementation.

This change adds a general window that overlays other windows, initially for the use case of picture in picture. This includes a partially stubbed views implementation. Cocoa work will be done in a separate CL.

BUG=726621

Review-Url: https://codereview.chromium.org/2905833004
Cr-Commit-Position: refs/heads/master@{#488150}
parent 0627c931
...@@ -792,6 +792,7 @@ split_static_library("ui") { ...@@ -792,6 +792,7 @@ split_static_library("ui") {
"omnibox/chrome_omnibox_navigation_observer.h", "omnibox/chrome_omnibox_navigation_observer.h",
"omnibox/clipboard_utils.cc", "omnibox/clipboard_utils.cc",
"omnibox/clipboard_utils.h", "omnibox/clipboard_utils.h",
"overlay/overlay_window.h",
"page_info/page_info_infobar_delegate.cc", "page_info/page_info_infobar_delegate.cc",
"page_info/page_info_infobar_delegate.h", "page_info/page_info_infobar_delegate.h",
"page_info/permission_menu_model.cc", "page_info/permission_menu_model.cc",
...@@ -1557,6 +1558,8 @@ split_static_library("ui") { ...@@ -1557,6 +1558,8 @@ split_static_library("ui") {
"views/login_view.h", "views/login_view.h",
"views/new_back_shortcut_bubble.cc", "views/new_back_shortcut_bubble.cc",
"views/new_back_shortcut_bubble.h", "views/new_back_shortcut_bubble.h",
"views/overlay/overlay_window_views.cc",
"views/overlay/overlay_window_views.h",
"views/page_info/chosen_object_row.cc", "views/page_info/chosen_object_row.cc",
"views/page_info/chosen_object_row.h", "views/page_info/chosen_object_row.h",
"views/page_info/chosen_object_row_observer.h", "views/page_info/chosen_object_row_observer.h",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_OVERLAY_OVERLAY_WINDOW_H_
#define CHROME_BROWSER_UI_OVERLAY_OVERLAY_WINDOW_H_
#include "base/memory/ptr_util.h"
#include "ui/gfx/native_widget_types.h"
namespace gfx {
class Rect;
}
namespace ui {
class Layer;
}
// This window will always float above other windows. The intention is to show
// content perpetually while the user is still interacting with the other
// browser windows.
class OverlayWindow {
public:
OverlayWindow() = default;
virtual ~OverlayWindow() = default;
// Returns a created OverlayWindow. This is defined in the platform-specific
// implementation for the class.
static std::unique_ptr<OverlayWindow> Create();
virtual void Init() = 0;
virtual bool IsActive() const = 0;
virtual void Show() = 0;
virtual void Hide() = 0;
virtual void Close() = 0;
virtual void Activate() = 0;
virtual bool IsAlwaysOnTop() const = 0;
virtual ui::Layer* GetLayer() = 0;
virtual gfx::NativeWindow GetNativeWindow() const = 0;
// Retrieves the window's current bounds, including its window.
virtual gfx::Rect GetBounds() const = 0;
private:
DISALLOW_COPY_AND_ASSIGN(OverlayWindow);
};
#endif // CHROME_BROWSER_UI_OVERLAY_OVERLAY_WINDOW_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/overlay/overlay_window_views.h"
#include "ui/views/widget/widget.h"
// static
std::unique_ptr<OverlayWindow> OverlayWindow::Create() {
return base::WrapUnique(new OverlayWindowViews());
}
OverlayWindowViews::OverlayWindowViews() {
widget_.reset(new views::Widget());
}
OverlayWindowViews::~OverlayWindowViews() = default;
void OverlayWindowViews::Init() {
// TODO(apacible): Finalize the type of widget. http://crbug/726621
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
// TODO(apacible): Update preferred sizing and positioning.
// http://crbug/726621
params.bounds = gfx::Rect(200, 200, 700, 500);
params.keep_on_top = true;
params.visible_on_all_workspaces = true;
widget_->Init(params);
widget_->Show();
// TODO(apacible): Set the WidgetDelegate for more control over behavior.
// http://crbug/726621
}
bool OverlayWindowViews::IsActive() const {
return widget_->IsActive();
}
void OverlayWindowViews::Show() {
widget_->Show();
}
void OverlayWindowViews::Hide() {
widget_->Hide();
}
void OverlayWindowViews::Close() {
widget_->Close();
}
void OverlayWindowViews::Activate() {
widget_->Activate();
}
bool OverlayWindowViews::IsAlwaysOnTop() const {
return true;
}
ui::Layer* OverlayWindowViews::GetLayer() {
return widget_->GetLayer();
}
gfx::NativeWindow OverlayWindowViews::GetNativeWindow() const {
return widget_->GetNativeWindow();
}
gfx::Rect OverlayWindowViews::GetBounds() const {
return widget_->GetRestoredBounds();
}
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_OVERLAY_OVERLAY_WINDOW_VIEWS_H_
#define CHROME_BROWSER_UI_VIEWS_OVERLAY_OVERLAY_WINDOW_VIEWS_H_
#include "chrome/browser/ui/overlay/overlay_window.h"
namespace views {
class Widget;
}
// The Views implementation of OverlayWindow.
class OverlayWindowViews : public OverlayWindow {
public:
OverlayWindowViews();
~OverlayWindowViews() override;
// OverlayWindow:
void Init() override;
bool IsActive() const override;
void Show() override;
void Hide() override;
void Close() override;
void Activate() override;
bool IsAlwaysOnTop() const override;
ui::Layer* GetLayer() override;
gfx::NativeWindow GetNativeWindow() const override;
gfx::Rect GetBounds() const override;
private:
std::unique_ptr<views::Widget> widget_;
DISALLOW_COPY_AND_ASSIGN(OverlayWindowViews);
};
#endif // CHROME_BROWSER_UI_VIEWS_OVERLAY_OVERLAY_WINDOW_VIEWS_H_
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