Commit 4d450a13 authored by mohsen's avatar mohsen Committed by Commit bot

mus: Allow SetModal to fail gracefully

Mus server might prevent some windows from becoming system modals. In
this case, SetModal would fail and the client needs to handle the
failure and revert the modality set locally for the window.

BUG=548402

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

Cr-Commit-Position: refs/heads/master@{#381871}
parent 38e785b0
...@@ -177,6 +177,8 @@ InFlightVisibleChange::InFlightVisibleChange(Window* window, ...@@ -177,6 +177,8 @@ InFlightVisibleChange::InFlightVisibleChange(Window* window,
: InFlightChange(window, ChangeType::VISIBLE), : InFlightChange(window, ChangeType::VISIBLE),
revert_visible_(revert_value) {} revert_visible_(revert_value) {}
InFlightVisibleChange::~InFlightVisibleChange() {}
void InFlightVisibleChange::SetRevertValueFrom(const InFlightChange& change) { void InFlightVisibleChange::SetRevertValueFrom(const InFlightChange& change) {
revert_visible_ = revert_visible_ =
static_cast<const InFlightVisibleChange&>(change).revert_visible_; static_cast<const InFlightVisibleChange&>(change).revert_visible_;
...@@ -186,4 +188,17 @@ void InFlightVisibleChange::Revert() { ...@@ -186,4 +188,17 @@ void InFlightVisibleChange::Revert() {
WindowPrivate(window()).LocalSetVisible(revert_visible_); WindowPrivate(window()).LocalSetVisible(revert_visible_);
} }
// InFlightSetModalChange ------------------------------------------------------
InFlightSetModalChange::InFlightSetModalChange(Window* window)
: InFlightChange(window, ChangeType::SET_MODAL) {}
InFlightSetModalChange::~InFlightSetModalChange() {}
void InFlightSetModalChange::SetRevertValueFrom(const InFlightChange& change) {}
void InFlightSetModalChange::Revert() {
WindowPrivate(window()).LocalUnsetModal();
}
} // namespace mus } // namespace mus
...@@ -253,6 +253,7 @@ class InFlightPredefinedCursorChange : public InFlightChange { ...@@ -253,6 +253,7 @@ class InFlightPredefinedCursorChange : public InFlightChange {
class InFlightVisibleChange : public InFlightChange { class InFlightVisibleChange : public InFlightChange {
public: public:
InFlightVisibleChange(Window* window, const bool revert_value); InFlightVisibleChange(Window* window, const bool revert_value);
~InFlightVisibleChange() override;
// InFlightChange: // InFlightChange:
void SetRevertValueFrom(const InFlightChange& change) override; void SetRevertValueFrom(const InFlightChange& change) override;
...@@ -264,6 +265,19 @@ class InFlightVisibleChange : public InFlightChange { ...@@ -264,6 +265,19 @@ class InFlightVisibleChange : public InFlightChange {
DISALLOW_COPY_AND_ASSIGN(InFlightVisibleChange); DISALLOW_COPY_AND_ASSIGN(InFlightVisibleChange);
}; };
class InFlightSetModalChange : public InFlightChange {
public:
explicit InFlightSetModalChange(Window* window);
~InFlightSetModalChange() override;
// InFlightChange:
void SetRevertValueFrom(const InFlightChange& change) override;
void Revert() override;
private:
DISALLOW_COPY_AND_ASSIGN(InFlightSetModalChange);
};
} // namespace mus } // namespace mus
#endif // COMPONENTS_MUS_PUBLIC_CPP_LIB_IN_FLIGHT_CHANGE_H_ #endif // COMPONENTS_MUS_PUBLIC_CPP_LIB_IN_FLIGHT_CHANGE_H_
...@@ -62,6 +62,7 @@ class WindowPrivate { ...@@ -62,6 +62,7 @@ class WindowPrivate {
void LocalRemoveTransientWindow(Window* child) { void LocalRemoveTransientWindow(Window* child) {
window_->LocalRemoveTransientWindow(child); window_->LocalRemoveTransientWindow(child);
} }
void LocalUnsetModal() { window_->is_modal_ = false; }
void LocalReorder(Window* relative, mojom::OrderDirection direction) { void LocalReorder(Window* relative, mojom::OrderDirection direction) {
window_->LocalReorder(relative, direction); window_->LocalReorder(relative, direction);
} }
......
...@@ -221,7 +221,7 @@ void WindowTreeClientImpl::RemoveTransientWindowFromParent(Window* window) { ...@@ -221,7 +221,7 @@ void WindowTreeClientImpl::RemoveTransientWindowFromParent(Window* window) {
void WindowTreeClientImpl::SetModal(Window* window) { void WindowTreeClientImpl::SetModal(Window* window) {
DCHECK(tree_); DCHECK(tree_);
const uint32_t change_id = ScheduleInFlightChange( const uint32_t change_id = ScheduleInFlightChange(
make_scoped_ptr(new CrashInFlightChange(window, ChangeType::SET_MODAL))); make_scoped_ptr(new InFlightSetModalChange(window)));
tree_->SetModal(change_id, window->id()); tree_->SetModal(change_id, window->id());
} }
......
...@@ -91,7 +91,10 @@ void TestWindowTree::RemoveTransientWindowFromParent( ...@@ -91,7 +91,10 @@ void TestWindowTree::RemoveTransientWindowFromParent(
uint32_t change_id, uint32_t change_id,
uint32_t transient_window_id) {} uint32_t transient_window_id) {}
void TestWindowTree::SetModal(uint32_t change_id, uint32_t window_id) {} void TestWindowTree::SetModal(uint32_t change_id, uint32_t window_id) {
got_change_ = true;
change_id_ = change_id;
}
void TestWindowTree::ReorderWindow(uint32_t change_id, void TestWindowTree::ReorderWindow(uint32_t change_id,
uint32_t window_id, uint32_t window_id,
......
...@@ -338,6 +338,20 @@ TEST_F(WindowTreeClientImplTest, SetVisibleFailedWithPendingChange) { ...@@ -338,6 +338,20 @@ TEST_F(WindowTreeClientImplTest, SetVisibleFailedWithPendingChange) {
EXPECT_EQ(original_visible, root->visible()); EXPECT_EQ(original_visible, root->visible());
} }
// Verifies |is_modal| is reverted if the server replied that the change failed.
TEST_F(WindowTreeClientImplTest, SetModalFailed) {
WindowTreeSetup setup;
Window* root = setup.GetFirstRoot();
ASSERT_TRUE(root);
EXPECT_FALSE(root->is_modal());
root->SetModal();
uint32_t change_id;
ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id));
EXPECT_TRUE(root->is_modal());
setup.window_tree_client()->OnChangeCompleted(change_id, false);
EXPECT_FALSE(root->is_modal());
}
TEST_F(WindowTreeClientImplTest, InputEventBasic) { TEST_F(WindowTreeClientImplTest, InputEventBasic) {
WindowTreeSetup setup; WindowTreeSetup setup;
Window* root = setup.GetFirstRoot(); Window* root = setup.GetFirstRoot();
......
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