Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / web_contents_modal_dialog_manager_cocoa.mm
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
3 // found in the LICENSE file.
4
5 #include "components/web_modal/web_contents_modal_dialog_manager.h"
6
7 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
8 #include "components/web_modal/single_web_contents_dialog_manager.h"
9
10 using web_modal::NativeWebContentsModalDialog;
11
12 namespace {
13
14 class NativeWebContentsModalDialogManagerCocoa
15     : public web_modal::SingleWebContentsDialogManager {
16  public:
17   NativeWebContentsModalDialogManagerCocoa(
18       NativeWebContentsModalDialog dialog)
19       : dialog_(dialog) {
20   }
21
22   virtual ~NativeWebContentsModalDialogManagerCocoa() {
23   }
24
25   // SingleWebContentsDialogManager overrides
26   virtual void Show() OVERRIDE {
27     GetConstrainedWindowMac(dialog())->ShowWebContentsModalDialog();
28   }
29
30   virtual void Hide() OVERRIDE {
31   }
32
33   virtual void Close() OVERRIDE {
34     GetConstrainedWindowMac(dialog())->CloseWebContentsModalDialog();
35   }
36
37   virtual void Focus() OVERRIDE {
38     GetConstrainedWindowMac(dialog())->FocusWebContentsModalDialog();
39   }
40
41   virtual void Pulse() OVERRIDE {
42     GetConstrainedWindowMac(dialog())->PulseWebContentsModalDialog();
43   }
44
45   virtual void HostChanged(
46       web_modal::WebContentsModalDialogHost* new_host) OVERRIDE {
47   }
48
49   virtual NativeWebContentsModalDialog dialog() OVERRIDE {
50     return dialog_;
51   }
52
53  private:
54   static ConstrainedWindowMac* GetConstrainedWindowMac(
55       NativeWebContentsModalDialog dialog) {
56     return static_cast<ConstrainedWindowMac*>(dialog);
57   }
58
59   // In mac this is a pointer to a ConstrainedWindowMac.
60   // TODO(gbillock): Replace this casting system with a more typesafe call path.
61   NativeWebContentsModalDialog dialog_;
62
63   DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerCocoa);
64 };
65
66 }  // namespace
67
68 namespace web_modal {
69
70 SingleWebContentsDialogManager*
71     WebContentsModalDialogManager::CreateNativeWebModalManager(
72         NativeWebContentsModalDialog dialog,
73         SingleWebContentsDialogManagerDelegate* native_delegate) {
74   return new NativeWebContentsModalDialogManagerCocoa(dialog);
75 }
76
77 }  // namespace web_modal