Commit edb06b84 authored by jackhou's avatar jackhou Committed by Commit bot

[MacViews] Add NativeAppWindowViewsMac and port HideWithApp behavior from NativeAppWindowCocoa.

Test coverage is provided by native_app_window_cocoa_browsertest.mm
which now uses whichever implementation of NativeAppWindow is
instantiated.

Added a new sources list to minimize having to change BUILD.gn when
more files are added.

BUG=459877

Review URL: https://codereview.chromium.org/975043003

Cr-Commit-Position: refs/heads/master@{#319153}
parent 86068833
......@@ -228,7 +228,10 @@ static_library("ui") {
}
if (is_mac) {
if (mac_views_browser) {
sources += [ "views/apps/chrome_app_window_client_views_mac.mm" ]
sources += rebase_path(
gypi_values.chrome_browser_ui_views_mac_experimental_sources,
".",
"//chrome")
sources -= [
"cocoa/apps/chrome_app_window_client_cocoa.mm",
"cocoa/bookmarks/bookmark_drag_drop_cocoa.mm",
......
......@@ -2,11 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h"
// This file tests whichever implementation of NativeAppWindow is used.
// I.e. it could be NativeAppWindowCocoa or ChromeNativeAppWindowViewsMac.
#include "extensions/browser/app_window/native_app_window.h"
#import <Cocoa/Cocoa.h>
#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsobject.h"
#include "base/mac/sdk_forward_declarations.h"
#include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/profiles/profile.h"
......
......@@ -4,13 +4,13 @@
#include "chrome/browser/ui/apps/chrome_app_window_client.h"
#include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h"
#include "chrome/browser/ui/views/apps/chrome_native_app_window_views_mac.h"
// static
extensions::NativeAppWindow* ChromeAppWindowClient::CreateNativeAppWindowImpl(
extensions::AppWindow* app_window,
const extensions::AppWindow::CreateParams& params) {
ChromeNativeAppWindowViews* window = new ChromeNativeAppWindowViews;
ChromeNativeAppWindowViewsMac* window = new ChromeNativeAppWindowViewsMac;
window->Init(app_window, params);
return window;
}
// Copyright 2015 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_APPS_CHROME_NATIVE_APP_WINDOW_VIEWS_MAC_H_
#define CHROME_BROWSER_UI_VIEWS_APPS_CHROME_NATIVE_APP_WINDOW_VIEWS_MAC_H_
#include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h"
// Mac-specific parts of ChromeNativeAppWindowViews.
class ChromeNativeAppWindowViewsMac : public ChromeNativeAppWindowViews {
public:
ChromeNativeAppWindowViewsMac();
~ChromeNativeAppWindowViewsMac() override;
protected:
// ui::BaseWindow implementation.
void Show() override;
void ShowInactive() override;
// NativeAppWindow implementation.
// These are used to simulate Mac-style hide/show. Since windows can be hidden
// and shown using the app.window API, this sets is_hidden_with_app_ to
// differentiate the reason a window was hidden.
void ShowWithApp() override;
void HideWithApp() override;
private:
// Whether this window last became hidden due to a request to hide the entire
// app, e.g. via the dock menu or Cmd+H. This is set by Hide/ShowWithApp.
bool is_hidden_with_app_;
DISALLOW_COPY_AND_ASSIGN(ChromeNativeAppWindowViewsMac);
};
#endif // CHROME_BROWSER_UI_VIEWS_APPS_CHROME_NATIVE_APP_WINDOW_VIEWS_MAC_H_
// Copyright 2015 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.
#import "chrome/browser/ui/views/apps/chrome_native_app_window_views_mac.h"
#include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h"
ChromeNativeAppWindowViewsMac::ChromeNativeAppWindowViewsMac()
: is_hidden_with_app_(false) {
}
ChromeNativeAppWindowViewsMac::~ChromeNativeAppWindowViewsMac() {
}
void ChromeNativeAppWindowViewsMac::Show() {
if (is_hidden_with_app_) {
// If there is a shim to gently request attention, return here. Otherwise
// show the window as usual.
if (apps::ExtensionAppShimHandler::ActivateAndRequestUserAttentionForWindow(
app_window())) {
return;
}
}
ChromeNativeAppWindowViews::Show();
}
void ChromeNativeAppWindowViewsMac::ShowInactive() {
if (is_hidden_with_app_)
return;
ChromeNativeAppWindowViews::ShowInactive();
}
void ChromeNativeAppWindowViewsMac::ShowWithApp() {
is_hidden_with_app_ = false;
if (!app_window()->is_hidden())
ShowInactive();
}
void ChromeNativeAppWindowViewsMac::HideWithApp() {
is_hidden_with_app_ = true;
ChromeNativeAppWindowViews::Hide();
}
......@@ -2309,6 +2309,14 @@
'browser/ui/views/website_settings/website_settings_popup_view.cc',
'browser/ui/views/website_settings/website_settings_popup_view.h',
],
# MacViews sources that we still want to keep behind a compile-time flag.
# TODO(jackhou): Move items to chrome_browser_ui_views_sources when they
# migrate from mac_views_browser to a chrome://flag.
'chrome_browser_ui_views_mac_experimental_sources': [
'browser/ui/views/apps/chrome_app_window_client_views_mac.mm',
'browser/ui/views/apps/chrome_native_app_window_views_mac.h',
'browser/ui/views/apps/chrome_native_app_window_views_mac.mm',
],
# Windows-only. Assume ash/aura/views.
'chrome_browser_ui_win_sources': [
'browser/ui/network_profile_bubble.cc',
......@@ -2858,7 +2866,7 @@
'conditions': [
['mac_views_browser==1', {
'sources': [
'browser/ui/views/apps/chrome_app_window_client_views_mac.mm',
'<@(chrome_browser_ui_views_mac_experimental_sources)',
],
'sources!': [
'browser/ui/cocoa/apps/chrome_app_window_client_cocoa.mm',
......
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