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

Side by Side Diff: chrome/browser/ui/views/base_shell_dialog_win.h

Issue 9203001: Implement input type=color UI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fixed issues/removed color_select_helper/added color_chooser_id Created 8 years, 10 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
(Empty)
1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_UI_VIEWS_BASE_SHELL_DIALOG_WIN_H_
6 #define CHROME_BROWSER_UI_VIEWS_BASE_SHELL_DIALOG_WIN_H_
7 #pragma once
8
9 #include <shlobj.h>
10 #include <set>
11
12 #include "base/threading/thread.h"
13 #include "chrome/browser/ui/base_shell_dialog.h"
14
15 // Helpers to show certain types of Windows shell dialogs in a way that doesn't
16 // block the UI of the entire app.
17
18 class ShellDialogThread : public base::Thread {
Peter Kasting 2012/02/07 01:46:24 Nit: This class can probably move to the .cc file.
keishi 2012/02/17 11:31:05 Done.
19 public:
20 ShellDialogThread() : base::Thread("Chrome_ShellDialogThread") { }
21 ~ShellDialogThread() {
22 Stop();
23 }
24
25 protected:
26 void Init() {
27 // Initializes the COM library on the current thread.
28 CoInitialize(NULL);
29 }
30
31 void CleanUp() {
32 // Closes the COM library on the current thread. CoInitialize must
33 // be balanced by a corresponding call to CoUninitialize.
34 CoUninitialize();
35 }
36
37 private:
38 DISALLOW_COPY_AND_ASSIGN(ShellDialogThread);
39 };
40
41 ///////////////////////////////////////////////////////////////////////////////
42 // A base class for all shell dialog implementations that handles showing a
43 // shell dialog modally on its own thread.
44 class BaseShellDialogImpl {
45 public:
46 BaseShellDialogImpl();
47 virtual ~BaseShellDialogImpl();
48
49 protected:
50 // Represents a run of a dialog.
51 struct RunState {
52 // Owning HWND, may be null.
53 HWND owner;
54
55 // Thread dialog is run on.
56 base::Thread* dialog_thread;
57 };
58
59 // Called at the beginning of a modal dialog run. Disables the owner window
60 // and tracks it. Returns the message loop of the thread that the dialog will
61 // be run on.
62 RunState BeginRun(HWND owner);
63
64 // Cleans up after a dialog run. If the run_state has a valid HWND this makes
65 // sure that the window is enabled. This is essential because BeginRun
66 // aggressively guards against multiple modal dialogs per HWND. Must be called
67 // on the UI thread after the result of the dialog has been determined.
68 //
69 // In addition this deletes the Thread in RunState.
70 void EndRun(RunState run_state);
71
72 // Returns true if a modal shell dialog is currently active for the specified
73 // owner. Must be called on the UI thread.
74 bool IsRunningDialogForOwner(HWND owner) const;
75
76 // Disables the window |owner|. Can be run from either the ui or the dialog
77 // thread. Can be called on either the UI or the dialog thread. This function
78 // is called on the dialog thread after the modal Windows Common dialog
79 // functions return because Windows automatically re-enables the owning
80 // window when those functions return, but we don't actually want them to be
81 // re-enabled until the response of the dialog propagates back to the UI
82 // thread, so we disable the owner manually after the Common dialog function
83 // returns.
84 void DisableOwner(HWND owner);
85
86 private:
87 // Creates a thread to run a shell dialog on. Each dialog requires its own
88 // thread otherwise in some situations where a singleton owns a single
89 // instance of this object we can have a situation where a modal dialog in
90 // one window blocks the appearance of a modal dialog in another.
91 static base::Thread* CreateDialogThread();
92
93 // Enables the window |owner_|. Can only be run from the ui thread.
94 void EnableOwner(HWND owner);
95
96 // A list of windows that currently own active shell dialogs for this
97 // instance. For example, if the DownloadManager owns an instance of this
98 // object and there are two browser windows open both with Save As dialog
99 // boxes active, this list will consist of the two browser windows' HWNDs.
100 // The derived class must call EndRun once the dialog is done showing to
101 // remove the owning HWND from this list.
102 // This object is static since it is maintained for all instances of this
103 // object - i.e. you can't have two file pickers open for the
104 // same owner, even though they might be represented by different instances
105 // of this object.
106 // This set only contains non-null HWNDs. NULL hwnds are not added to this
107 // list.
108 typedef std::set<HWND> Owners;
Peter Kasting 2012/02/07 01:46:24 Nit: This typedef belongs atop the private section
keishi 2012/02/17 11:31:05 Done.
109 static Owners owners_;
110 static int instance_count_;
111
112 DISALLOW_COPY_AND_ASSIGN(BaseShellDialogImpl);
113 };
114
115 #endif // CHROME_BROWSER_UI_VIEWS_BASE_SHELL_DIALOG_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698