Skip to content

Commit

Permalink
[Eche] Create mojo interface for orientation changes
Browse files Browse the repository at this point in the history
This change introduces a mojo interface that allows the web UI to signal
to the bubble to switch between horizontal and vertical orientations.
Follow-up CLs will handle the usage of the signal from the web UI side
and the orientation change on the C++ views side.

Test: verified that Phone Hub and App Streaming work properly.
Bug: b/258306301
Change-Id: I56c2dca7305068c3b95649c0937257da9ef780ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4202054
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Abbas Nayebi <nayebi@google.com>
Commit-Queue: Crisrael Lucero <crisrael@google.com>
Reviewed-by: Jon Mann <jonmann@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1101207}
  • Loading branch information
crisrael authored and Chromium LUCI CQ committed Feb 3, 2023
1 parent f2d8761 commit fbe0d5b
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 2 deletions.
19 changes: 18 additions & 1 deletion ash/system/eche/eche_tray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,13 @@ gfx::Size EcheTray::CalculateSizeForEche() const {
(static_cast<float>(work_area_bounds.height()) * kMaxHeightPercentage) /
kDefaultBubbleSize.height();
height_scale = std::min(height_scale, 1.0f);
return gfx::ScaleToFlooredSize(kDefaultBubbleSize, height_scale);
gfx::Size size = gfx::ScaleToFlooredSize(kDefaultBubbleSize, height_scale);

if (stream_orientation_ == eche_app::mojom::StreamOrientation::kLandscape) {
size = gfx::Size(size.height(), size.width());
}

return size;
}

void EcheTray::OnArrowBackActivated() {
Expand Down Expand Up @@ -774,11 +780,22 @@ void EcheTray::OnTabletModeStarted() {
void EcheTray::OnTabletModeEnded() {
UpdateEcheSizeAndBubbleBounds();
}

void EcheTray::OnShelfAlignmentChanged(aura::Window* root_window,
ShelfAlignment old_alignment) {
UpdateEcheSizeAndBubbleBounds();
}

void EcheTray::OnStreamOrientationChanged(
eche_app::mojom::StreamOrientation orientation) {
if (stream_orientation_ == orientation) {
return;
}

stream_orientation_ = orientation;
UpdateEcheSizeAndBubbleBounds();
}

gfx::Rect EcheTray::GetAnchor() {
return shelf()->GetSystemTrayAnchorRect();
}
Expand Down
16 changes: 15 additions & 1 deletion ash/system/eche/eche_tray.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class ASH_EXPORT EcheTray : public TrayBackgroundView,
public ShelfObserver,
public TabletModeObserver,
public KeyboardControllerObserver,
public ShellObserver {
public ShellObserver,
public eche_app::mojom::StreamOrientationObserver {
public:
METADATA_HEADER(EcheTray);

Expand Down Expand Up @@ -148,6 +149,10 @@ class ASH_EXPORT EcheTray : public TrayBackgroundView,
void OnKeyboardUIDestroyed() override;
void OnKeyboardHidden(bool is_temporary_hide) override;

// eche_app::mojom::StreamOrientationObserver:
void OnStreamOrientationChanged(
eche_app::mojom::StreamOrientation orientation) override;

// Sets the url that will be passed to the webview.
// Setting a new value will cause the current bubble be destroyed.
void SetUrl(const GURL& url);
Expand Down Expand Up @@ -216,6 +221,9 @@ class ASH_EXPORT EcheTray : public TrayBackgroundView,
void StartGracefulClose();

// Test helpers
eche_app::mojom::StreamOrientation get_stream_orientation_for_test() {
return stream_orientation_;
}
TrayBubbleWrapper* get_bubble_wrapper_for_test() { return bubble_.get(); }
AshWebView* get_web_view_for_test() { return web_view_; }
views::ImageButton* GetIcon();
Expand All @@ -225,6 +233,7 @@ class ASH_EXPORT EcheTray : public TrayBackgroundView,
FRIEND_TEST_ALL_PREFIXES(EcheTrayTest, EcheTrayOnDisplayConfigurationChanged);
FRIEND_TEST_ALL_PREFIXES(EcheTrayTest,
EcheTrayKeyboardShowHideUpdateBubbleBounds);
FRIEND_TEST_ALL_PREFIXES(EcheTrayTest, EcheTrayOnStreamOrientationChanged);

// Intercepts all the events targeted to the internal webview in order to
// process the accelerator keys.
Expand Down Expand Up @@ -325,6 +334,11 @@ class ASH_EXPORT EcheTray : public TrayBackgroundView,
// when the stream is initializing to when the stream is closed by user.
absl::optional<base::TimeTicks> init_stream_timestamp_;

// The orientation of the stream (portrait vs landscape). The default
// orientation is portrait.
eche_app::mojom::StreamOrientation stream_orientation_ =
eche_app::mojom::StreamOrientation::kPortrait;

bool is_stream_started_ = false;
std::u16string phone_name_;

Expand Down
43 changes: 43 additions & 0 deletions ash/system/eche/eche_tray_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,49 @@ TEST_F(EcheTrayTest, EcheTrayKeyboardShowHideUpdateBubbleBounds) {
eche_tray()->get_web_view_for_test()->height() + kBubbleMenuPadding * 2);
}

TEST_F(EcheTrayTest, EcheTrayOnStreamOrientationChanged) {
gfx::Size expected_eche_size = eche_tray()->CalculateSizeForEche();
eche_tray()->LoadBubble(GURL("http://google.com"), CreateTestImage(),
u"app 1", u"your phone");
eche_tray()->ShowBubble();

EXPECT_EQ(eche_tray()->get_stream_orientation_for_test(),
eche_app::mojom::StreamOrientation::kPortrait);
EXPECT_EQ(expected_eche_size.width(),
eche_tray()->get_bubble_wrapper_for_test()->bubble_view()->width());
EXPECT_EQ(
expected_eche_size.height(),
eche_tray()->get_web_view_for_test()->height() + kBubbleMenuPadding * 2);

// Orientation should stay the same
eche_tray()->OnStreamOrientationChanged(
eche_app::mojom::StreamOrientation::kPortrait);
EXPECT_EQ(eche_tray()->get_stream_orientation_for_test(),
eche_app::mojom::StreamOrientation::kPortrait);

expected_eche_size = eche_tray()->CalculateSizeForEche();

EXPECT_EQ(expected_eche_size.width(),
eche_tray()->get_bubble_wrapper_for_test()->bubble_view()->width());
EXPECT_EQ(
expected_eche_size.height(),
eche_tray()->get_web_view_for_test()->height() + kBubbleMenuPadding * 2);

// Change orientation
eche_tray()->OnStreamOrientationChanged(
eche_app::mojom::StreamOrientation::kLandscape);
EXPECT_EQ(eche_tray()->get_stream_orientation_for_test(),
eche_app::mojom::StreamOrientation::kLandscape);

expected_eche_size = eche_tray()->CalculateSizeForEche();
EXPECT_EQ(
expected_eche_size.width(),
eche_tray()->get_web_view_for_test()->width() + kBubbleMenuPadding * 2);
EXPECT_EQ(
expected_eche_size.height(),
eche_tray()->get_web_view_for_test()->height() + kBubbleMenuPadding * 2);
}

TEST_F(EcheTrayTest, DISABLED_OnThemeChanged) {
ResetUnloadWebContent();
eche_tray()->LoadBubble(GURL("http://google.com"), CreateTestImage(),
Expand Down
12 changes: 12 additions & 0 deletions ash/webui/eche_app_ui/mojom/eche_app.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ interface StreamActionObserver {
OnStreamAction(StreamAction action);
};

// Enum representing orientations for the app stream.
enum StreamOrientation {
kPortrait,
kLandscape,
};

// Interface to send new orientation for the app streaming bubble from Eche SWA.
interface StreamOrientationObserver {
// Notifies what orientation the stream has changed to.
OnStreamOrientationChanged(StreamOrientation orientation);
};

// Enum representing what EntryPoint was used to launch the eche app stream.
// Keep in sync with AppStreamLaunchEntryPoint in
// tools/metrics/histograms/enums.xml
Expand Down
10 changes: 10 additions & 0 deletions ash/webui/eche_app_ui/resources/browser_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const notificationGenerator =

const displayStreamHandler = ash.echeApp.mojom.DisplayStreamHandler.getRemote();

const streamOrientationObserver =
ash.echeApp.mojom.StreamOrientationObserver.getRemote();

const streamActionObserverRouter =
new ash.echeApp.mojom.StreamActionObserverCallbackRouter();
// Set up a message pipe to the browser process to monitor stream action.
Expand Down Expand Up @@ -189,6 +192,13 @@ guestMessagePipe.registerHandler(Message.START_STREAMING, async () => {
ash.echeApp.mojom.StreamStatus.kStreamStatusStarted);
});

// Register CHANGE_ORIENTATION.
guestMessagePipe.registerHandler(
Message.CHANGE_ORIENTATION, async (orientation) => {
console.log(`echeapi browser_proxy.js ${orientation}`);
streamOrientationObserver.onStreamOrientationChanged(orientation);
});

// We can't access hash change event inside iframe so parse the notification
// info from the anchor part of the url when hash is changed and send them to
// untrusted section via message pipes.
Expand Down
2 changes: 2 additions & 0 deletions ash/webui/eche_app_ui/resources/message_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@
IS_VIRTUAL_KEYBOARD_ENABLED: 'is_virtual_keyboard_enabled',
// Message for Android network info
ANDROID_NETWORK_INFO: 'android-network-info',
// Message for changing app stream orientation
CHANGE_ORIENTATION: 'change_orientation',
};
7 changes: 7 additions & 0 deletions ash/webui/eche_app_ui/resources/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ const EcheApiBindingImpl = new (class {
streamActionCallback = callback;
}

onStreamOrientationChanged(orientation) {
console.log('echeapi receiver.js onStreamOrientationChanged');
parentMessagePipe.sendMessage(Message.CHANGE_ORIENTATION, {orientation});
}

onReceivedVirtualKeyboardChanged(callback) {
console.log('echeapi receiver.js onReceivedVirtualKeyboardChanged');
virtualKeyboardCallback = callback;
Expand Down Expand Up @@ -203,5 +208,7 @@ echeapi.system.registerVirtualKeyboardChangedReceiver =
echeapi.system.registerAndroidNetworkInfoChangedReceiver =
EcheApiBindingImpl.onAndroidDeviceNetworkInfoChanged.bind(
EcheApiBindingImpl);
echeapi.system.registerStreamOrientationReceiver =
EcheApiBindingImpl.onStreamOrientationChanged.bind(EcheApiBindingImpl);
window['echeapi'] = echeapi;
console.log('echeapi receiver.js finish bind the implementation of echeapi');

0 comments on commit fbe0d5b

Please sign in to comment.