Skip to content

Commit

Permalink
Add drop shadow to popups on Mac.
Browse files Browse the repository at this point in the history
This change adds drop shadow to popups for FormControlsRefresh by using
the [NSWindow hasShadow] property.

Since the Mac window shadow also has its own border, the HTML provided
border for the popups [1] is changed to be transparent to avoid having a
weird UI.

[1]: https://chromium-review.googlesource.com/c/chromium/src/+/2036250

Bug: 1000898
Change-Id: Iadf89e7a122614b6dba95b745be2af79476da98d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2052264
Commit-Queue: Ionel Popescu <iopopesc@microsoft.com>
Reviewed-by: ccameron <ccameron@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Reviewed-by: Mason Freed <masonfreed@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741588}
  • Loading branch information
ipopescu93 authored and Commit Bot committed Feb 14, 2020
1 parent 80388f4 commit e4bca2f
Show file tree
Hide file tree
Showing 114 changed files with 47 additions and 10 deletions.
1 change: 1 addition & 0 deletions content/app_shim_remote_cocoa/popup_window_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace remote_cocoa {
class PopupWindowMac {
public:
PopupWindowMac(const gfx::Rect& content_rect,
bool has_shadow,
RenderWidgetHostViewCocoa* cocoa_view);
~PopupWindowMac();

Expand Down
2 changes: 2 additions & 0 deletions content/app_shim_remote_cocoa/popup_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ - (void)stopObservingClicks {
namespace remote_cocoa {

PopupWindowMac::PopupWindowMac(const gfx::Rect& content_rect,
bool has_shadow,
RenderWidgetHostViewCocoa* cocoa_view)
: cocoa_view_(cocoa_view) {
[cocoa_view_ setCloseOnDeactivate:YES];
Expand All @@ -93,6 +94,7 @@ - (void)stopObservingClicks {
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO]);
[popup_window_ setHasShadow:has_shadow];
[popup_window_ setLevel:NSPopUpMenuWindowLevel];
[popup_window_ setReleasedWhenClosed:NO];
[popup_window_ makeKeyAndOrderFront:nil];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RenderWidgetHostNSViewBridge : public mojom::RenderWidgetHostNSView,
RenderWidgetHostViewCocoa* GetNSView();

// mojom::RenderWidgetHostNSView implementation.
void InitAsPopup(const gfx::Rect& content_rect) override;
void InitAsPopup(const gfx::Rect& content_rect, bool has_shadow) override;
void SetParentWebContentsNSView(uint64_t parent_ns_view_id) override;
void DisableDisplay() override;
void MakeFirstResponder() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@
return cocoa_view_;
}

void RenderWidgetHostNSViewBridge::InitAsPopup(const gfx::Rect& content_rect) {
popup_window_ = std::make_unique<PopupWindowMac>(content_rect, cocoa_view_);
void RenderWidgetHostNSViewBridge::InitAsPopup(const gfx::Rect& content_rect,
bool has_shadow) {
popup_window_ =
std::make_unique<PopupWindowMac>(content_rect, has_shadow, cocoa_view_);
}

void RenderWidgetHostNSViewBridge::SetParentWebContentsNSView(
Expand Down
5 changes: 4 additions & 1 deletion content/browser/renderer_host/render_widget_host_view_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@
popup_parent_host_view_->popup_child_host_view_ = this;

// This path is used by the time/date picker.
ns_view_->InitAsPopup(pos);
// When FormControlsRefresh is enabled the popup window should use
// the native shadow.
bool has_shadow = features::IsFormControlsRefreshEnabled();
ns_view_->InitAsPopup(pos, has_shadow);
}

void RenderWidgetHostViewMac::InitAsFullscreen(
Expand Down
2 changes: 1 addition & 1 deletion content/common/render_widget_host_ns_view.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import "ui/gfx/range/mojom/range.mojom";
interface RenderWidgetHostNSView {
// Specify that the NSView will a popup (e.g, date/time picker) that will
// create its own NSWindow.
InitAsPopup(gfx.mojom.Rect content_rect);
InitAsPopup(gfx.mojom.Rect content_rect, bool has_shadow);

// Set this to be a child NSView of the NSView mapped to by
// |parent_ns_view_id|.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "third_party/blink/renderer/core/html/forms/color_chooser_popup_ui_controller.h"

#include "build/build_config.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/strings/grit/blink_strings.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
Expand Down Expand Up @@ -99,7 +100,6 @@ void ColorChooserPopupUIController::WriteColorPickerDocument(
"<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", data);
data->Append(ChooserResourceLoader::GetPickerCommonStyleSheet());
data->Append(ChooserResourceLoader::GetColorPickerStyleSheet());

PagePopupClient::AddString(
"</style></head><body>\n"
"<div id='main'>Loading...</div><script>\n"
Expand All @@ -110,6 +110,10 @@ void ColorChooserPopupUIController::WriteColorPickerDocument(
AddProperty("anchorRectInScreen", anchor_rect_in_screen, data);
AddProperty("zoomFactor", ScaledZoomFactor(), data);
AddProperty("shouldShowColorSuggestionPicker", false, data);
#if defined(OS_MACOSX)
AddProperty("isBorderTransparent", features::IsFormControlsRefreshEnabled(),
data);
#endif
PagePopupClient::AddString("};\n", data);
data->Append(ChooserResourceLoader::GetPickerCommonJS());
data->Append(ChooserResourceLoader::GetColorPickerJS());
Expand All @@ -131,9 +135,6 @@ void ColorChooserPopupUIController::WriteColorSuggestionPickerDocument(
"<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", data);
data->Append(ChooserResourceLoader::GetPickerCommonStyleSheet());
data->Append(ChooserResourceLoader::GetColorSuggestionPickerStyleSheet());
if (features::IsFormControlsRefreshEnabled())
data->Append(ChooserResourceLoader::GetColorPickerStyleSheet());

PagePopupClient::AddString(
"</style></head><body>\n"
"<div id='main'>Loading...</div><script>\n"
Expand All @@ -152,6 +153,10 @@ void ColorChooserPopupUIController::WriteColorSuggestionPickerDocument(
AddProperty("shouldShowColorSuggestionPicker", true, data);
AddProperty("isFormControlsRefreshEnabled",
features::IsFormControlsRefreshEnabled(), data);
#if defined(OS_MACOSX)
AddProperty("isBorderTransparent", features::IsFormControlsRefreshEnabled(),
data);
#endif
PagePopupClient::AddString("};\n", data);
data->Append(ChooserResourceLoader::GetPickerCommonJS());
data->Append(ChooserResourceLoader::GetColorSuggestionPickerJS());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "third_party/blink/renderer/core/html/forms/date_time_chooser_impl.h"

#include "build/build_config.h"
#include "third_party/blink/public/mojom/choosers/date_time_chooser.mojom-blink.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/strings/grit/blink_strings.h"
Expand Down Expand Up @@ -177,6 +178,10 @@ void DateTimeChooserImpl::WriteDocument(SharedBuffer* data) {
AddProperty("isRTL", parameters_->is_anchor_element_rtl, data);
AddProperty("isFormControlsRefreshEnabled",
features::IsFormControlsRefreshEnabled(), data);
#if defined(OS_MACOSX)
AddProperty("isBorderTransparent", features::IsFormControlsRefreshEnabled(),
data);
#endif
AddProperty("mode", parameters_->type.GetString(), data);
AddProperty("isAMPMFirst", parameters_->is_ampm_first, data);
AddProperty("hasAMPM", parameters_->has_ampm, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var global = {
],
isLocaleRTL: false,
isFormControlsRefreshEnabled: false,
isBorderTransparent: false,
mode: 'date',
isAMPMFirst: false,
hasAMPM: false,
Expand Down Expand Up @@ -4325,7 +4326,9 @@ CalendarTableView.prototype.throwAwayWeekNumberCell = function(weekNumberCell) {
function CalendarPicker(type, config) {
View.call(this, createElement('div', CalendarPicker.ClassNameCalendarPicker));
this.element.classList.add(CalendarPicker.ClassNamePreparing);

if (global.params.isBorderTransparent) {
this.element.style.borderColor = 'transparent';
}
/**
* @type {!string}
* @const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,10 @@ class ColorPicker extends HTMLElement {
constructor(initialColor) {
super();

if (global.params.isBorderTransparent) {
this.style.borderColor = 'transparent';
}

this.selectedColor_ = initialColor;
this.colorWhenOpened_ = initialColor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ function initialize(args) {
document.body.classList.add('controls-refresh');
}
main.classList.add('color-suggestion-picker-main');
if (global.params.isBorderTransparent) {
main.style.borderColor = 'transparent';
}
errorString = validateColorSuggestionPickerArguments(args);
} else {
main.classList.add('color-picker-main');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ function initializeMonthPicker(config) {
global.picker = new MonthPicker(config);
main.append(global.picker);
main.style.border = '1px solid #bfbfbf';
if (global.params.isBorderTransparent) {
main.style.borderColor = 'transparent';
}
main.style.height = (MonthPicker.Height - 2) + 'px';
main.style.width = (MonthPicker.Width - 2) + 'px';
resizeWindow(MonthPicker.Width, MonthPicker.Height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ SuggestionPicker.prototype._layout = function() {
if (this._config.isLocaleRTL)
this._element.classList.add('locale-rtl');
this._containerElement = createElement('ul', 'suggestion-list');
if (global.params.isBorderTransparent) {
this._containerElement.style.borderColor = 'transparent';
}
this._containerElement.addEventListener(
'click', this._handleEntryClick.bind(this), false);
for (var i = 0; i < this._config.suggestionValues.length; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ class TimePicker extends HTMLElement {
super();

this.className = TimePicker.ClassName;
if (global.params.isBorderTransparent) {
this.style.borderColor = 'transparent';
}
this.initializeFromConfig_(config);

this.timeColumns_ = new TimeColumns(this);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e4bca2f

Please sign in to comment.