-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is likely to change over time as we get more advanced animation and positioning, but this provides an acceptable initial experience. Bug: b:305019677 Change-Id: Ideff0ca5ba6ba2f92e4946f109fc976e11b4f411 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4953087 Reviewed-by: Scott Violet <sky@chromium.org> Reviewed-by: Anthony Cui <cuianthony@chromium.org> Commit-Queue: Justin DeWitt <dewittj@chromium.org> Cr-Commit-Position: refs/heads/main@{#1212409}
- Loading branch information
Showing
19 changed files
with
204 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
html, body { | ||
cursor: default; | ||
margin: 0; | ||
min-width: 448px; | ||
overflow: hidden; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
chrome/browser/ui/views/compose/chrome_compose_dialog_controller.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// 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/compose/chrome_compose_dialog_controller.h" | ||
|
||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/ui/browser_dialogs.h" | ||
#include "chrome/browser/ui/browser_finder.h" | ||
#include "chrome/browser/ui/views/bubble/webui_bubble_dialog_view.h" | ||
#include "chrome/browser/ui/views/frame/browser_view.h" | ||
#include "ui/views/bubble/bubble_border.h" | ||
#include "ui/views/bubble/bubble_dialog_delegate_view.h" | ||
|
||
// Default size from Figma spec. The size of the view will follow the requested | ||
// size of the WebUI, once these are connected. | ||
namespace { | ||
|
||
const char kComposeURL[] = "chrome://compose/"; | ||
|
||
} | ||
|
||
namespace chrome { | ||
|
||
std::unique_ptr<compose::ComposeDialogController> ShowComposeDialog( | ||
content::WebContents& web_contents, | ||
const gfx::RectF& element_bounds_in_screen) { | ||
auto controller = | ||
std::make_unique<ChromeComposeDialogController>(&web_contents); | ||
controller->ShowComposeDialog(nullptr, element_bounds_in_screen); | ||
return controller; | ||
} | ||
|
||
} // namespace chrome | ||
|
||
ChromeComposeDialogController::~ChromeComposeDialogController() = default; | ||
|
||
// TOOD(b/301371110): This function should accept an argument indicating whether | ||
// it was called from the context menu. If so, open by popping in. Otherwise, | ||
// open with an expanding animation. | ||
void ChromeComposeDialogController::ShowComposeDialog( | ||
views::View* anchor_view, | ||
const gfx::RectF& element_bounds_in_screen) { | ||
if (!web_contents_) { | ||
return; | ||
} | ||
|
||
Profile* profile = | ||
Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | ||
bubble_wrapper_ = std::make_unique<BubbleContentsWrapperT<ComposeUI>>( | ||
GURL(kComposeURL), profile, IDS_COMPOSE_TITLE); | ||
bubble_wrapper_->ReloadWebContents(); | ||
|
||
// This WebUI needs to know the calling BrowserContents so that the compose | ||
// request/result can be properly associated with the triggering form. | ||
bubble_wrapper_->GetWebUIController()->set_triggering_web_contents( | ||
web_contents_.get()); | ||
|
||
auto bubble_view = std::make_unique<WebUIBubbleDialogView>( | ||
anchor_view, bubble_wrapper_.get(), | ||
gfx::ToRoundedRect(element_bounds_in_screen)); | ||
|
||
// Allows the bubble bounds to escape the browser window. | ||
bubble_view->set_has_parent(false); | ||
|
||
auto weak_ptr = bubble_view->GetWeakPtr(); | ||
views::BubbleDialogDelegateView::CreateBubble(std::move(bubble_view)); | ||
|
||
weak_ptr->ShowUI(); | ||
} | ||
|
||
BubbleContentsWrapperT<ComposeUI>* | ||
ChromeComposeDialogController::GetBubbleWrapper() const { | ||
return bubble_wrapper_.get(); | ||
} | ||
|
||
// TODO(b/300939629): Flesh out implementation and cover other closing paths. | ||
void ChromeComposeDialogController::Close() { | ||
bubble_wrapper_->CloseUI(); | ||
bubble_wrapper_.reset(); | ||
} | ||
|
||
ChromeComposeDialogController::ChromeComposeDialogController( | ||
content::WebContents* web_contents) | ||
: web_contents_(web_contents->GetWeakPtr()) {} |
47 changes: 47 additions & 0 deletions
47
chrome/browser/ui/views/compose/chrome_compose_dialog_controller.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// 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_COMPOSE_CHROME_COMPOSE_DIALOG_CONTROLLER_H_ | ||
#define CHROME_BROWSER_UI_VIEWS_COMPOSE_CHROME_COMPOSE_DIALOG_CONTROLLER_H_ | ||
|
||
#include "base/memory/weak_ptr.h" | ||
#include "chrome/browser/ui/views/bubble/bubble_contents_wrapper.h" | ||
#include "chrome/browser/ui/views/compose/compose_dialog_view.h" | ||
#include "chrome/browser/ui/webui/compose/compose_ui.h" | ||
#include "components/compose/core/browser/compose_dialog_controller.h" | ||
#include "components/strings/grit/components_strings.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "content/public/browser/web_contents_user_data.h" | ||
|
||
namespace gfx { | ||
class RectF; | ||
} | ||
|
||
// Controls how Compose dialogs are shown and hidden, and animations related to | ||
// both actions. | ||
class ChromeComposeDialogController : public compose::ComposeDialogController { | ||
public: | ||
explicit ChromeComposeDialogController(content::WebContents* contents); | ||
~ChromeComposeDialogController() override; | ||
|
||
// Create and show the dialog view. | ||
void ShowComposeDialog(views::View* anchor_view, | ||
const gfx::RectF& element_bounds_in_screen); | ||
|
||
// Returns the currently shown compose dialog. Returns nullptr if the dialog | ||
// is not currently shown. | ||
BubbleContentsWrapperT<ComposeUI>* GetBubbleWrapper() const; | ||
|
||
void Close() override; | ||
|
||
private: | ||
friend class ChromeComposeDialogControllerTest; | ||
|
||
std::unique_ptr<BubbleContentsWrapperT<ComposeUI>> bubble_wrapper_; | ||
base::WeakPtr<content::WebContents> web_contents_; | ||
|
||
base::WeakPtrFactory<ChromeComposeDialogController> weak_ptr_factory_{this}; | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_VIEWS_COMPOSE_CHROME_COMPOSE_DIALOG_CONTROLLER_H_ |
94 changes: 0 additions & 94 deletions
94
chrome/browser/ui/views/compose/compose_dialog_controller.cc
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.