Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(743)

Side by Side Diff: chrome/browser/ui/cocoa/web_contents_modal_dialog_manager_cocoa.mm

Issue 866263008: MacViews: Unify web contents modal dialog types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ValidationMessageBubble
Patch Set: Another idea Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/web_modal/web_contents_modal_dialog_manager.h" 5 #include "components/web_modal/web_contents_modal_dialog_manager.h"
6 6
7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sh eet.h"
7 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h" 8 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
8 #include "components/web_modal/single_web_contents_dialog_manager.h" 9 #include "components/web_modal/single_web_contents_dialog_manager.h"
9 10
10 using web_modal::NativeWebContentsModalDialog; 11 using web_modal::NativeWebContentsModalDialog;
12 using web_modal::SingleWebContentsDialogManagerDelegate;
11 13
12 namespace { 14 namespace {
13 15
14 class NativeWebContentsModalDialogManagerCocoa 16 class NativeWebContentsModalDialogManagerCocoa
15 : public web_modal::SingleWebContentsDialogManager { 17 : public web_modal::SingleWebContentsDialogManager {
16 public: 18 public:
17 NativeWebContentsModalDialogManagerCocoa( 19 NativeWebContentsModalDialogManagerCocoa(
18 NativeWebContentsModalDialog dialog) 20 NativeWebContentsModalDialog dialog,
19 : dialog_(dialog) { 21 SingleWebContentsDialogManagerDelegate* native_delegate)
22 : native_delegate_(native_delegate),
23 dialog_(dialog),
24 sheet_([[CustomConstrainedWindowSheet alloc]
25 initWithCustomWindow:dialog]) {}
26
27 ~NativeWebContentsModalDialogManagerCocoa() override {
28 Close();
20 } 29 }
21 30
22 ~NativeWebContentsModalDialogManagerCocoa() override {} 31 // SingleWebContentsDialogManager overrides.
23
24 // SingleWebContentsDialogManager overrides
25 void Show() override { 32 void Show() override {
26 GetConstrainedWindowMac(dialog())->ShowWebContentsModalDialog(); 33 window_.reset(new ConstrainedWindowMac(
Mike Wittman 2015/02/25 20:40:53 I think this preserves the existing creation/show/
34 nullptr, native_delegate_->GetWebContents(), sheet_));
27 } 35 }
28 36
29 void Hide() override {} 37 void Hide() override {}
30 38
31 void Close() override { 39 void Close() override {
32 GetConstrainedWindowMac(dialog())->CloseWebContentsModalDialog(); 40 window_->CloseWebContentsModalDialog();
Mike Wittman 2015/02/25 20:40:53 Add null check. window_ can be null here if the di
33 } 41 }
34 42
35 void Focus() override { 43 void Focus() override {
36 GetConstrainedWindowMac(dialog())->FocusWebContentsModalDialog(); 44 window_->FocusWebContentsModalDialog();
Mike Wittman 2015/02/25 20:40:53 DCHECK(window_.get()) This shouldn't get called u
37 } 45 }
38 46
39 void Pulse() override { 47 void Pulse() override {
40 GetConstrainedWindowMac(dialog())->PulseWebContentsModalDialog(); 48 window_->PulseWebContentsModalDialog();
Mike Wittman 2015/02/25 20:40:53 Ditto.
41 } 49 }
42 50
43 void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override {} 51 void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override {}
44 52
45 NativeWebContentsModalDialog dialog() override { return dialog_; } 53 NativeWebContentsModalDialog dialog() override { return dialog_; }
46 54
47 private: 55 private:
48 static ConstrainedWindowMac* GetConstrainedWindowMac( 56 SingleWebContentsDialogManagerDelegate* native_delegate_;
tapted 2015/02/25 06:23:28 Lifetime comment?
49 NativeWebContentsModalDialog dialog) {
50 return static_cast<ConstrainedWindowMac*>(dialog);
51 }
52
53 // In mac this is a pointer to a ConstrainedWindowMac.
54 // TODO(gbillock): Replace this casting system with a more typesafe call path.
55 NativeWebContentsModalDialog dialog_; 57 NativeWebContentsModalDialog dialog_;
58 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet_;
59 scoped_ptr<ConstrainedWindowMac> window_;
56 60
57 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerCocoa); 61 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerCocoa);
58 }; 62 };
59 63
60 } // namespace 64 } // namespace
61 65
62 namespace web_modal { 66 namespace web_modal {
63 67
64 SingleWebContentsDialogManager* 68 SingleWebContentsDialogManager*
65 WebContentsModalDialogManager::CreateNativeWebModalManager( 69 WebContentsModalDialogManager::CreateNativeWebModalManager(
66 NativeWebContentsModalDialog dialog, 70 NativeWebContentsModalDialog dialog,
67 SingleWebContentsDialogManagerDelegate* native_delegate) { 71 SingleWebContentsDialogManagerDelegate* native_delegate) {
68 return new NativeWebContentsModalDialogManagerCocoa(dialog); 72 return new NativeWebContentsModalDialogManagerCocoa(dialog, native_delegate);
69 } 73 }
70 74
71 } // namespace web_modal 75 } // namespace web_modal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698