OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 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 "chrome_frame/ready_mode/internal/ready_prompt_content.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "chrome_frame/ready_mode/internal/ready_mode_state.h" | |
9 #include "chrome_frame/ready_mode/internal/ready_prompt_window.h" | |
10 #include "chrome_frame/ready_mode/internal/url_launcher.h" | |
11 | |
12 ReadyPromptContent::ReadyPromptContent(ReadyModeState* ready_mode_state, | |
13 UrlLauncher* url_launcher) | |
14 : ready_mode_state_(ready_mode_state), | |
15 url_launcher_(url_launcher) { | |
16 } | |
17 | |
18 ReadyPromptContent::~ReadyPromptContent() { | |
19 if (window_ != NULL && window_->IsWindow()) { | |
20 // The window must discard its ContentFrame pointer at this time. | |
21 window_->DestroyWindow(); | |
22 window_.reset(); | |
23 } | |
24 } | |
25 | |
26 bool ReadyPromptContent::InstallInFrame(Frame* frame) { | |
27 DCHECK(window_ == NULL); | |
28 DCHECK(ready_mode_state_ != NULL); | |
29 DCHECK(url_launcher_ != NULL); | |
30 | |
31 // Pass ownership of our ready_mode_state_ and url_launcher_ to the window. | |
32 window_ = ReadyPromptWindow::CreateInstance( | |
33 frame, ready_mode_state_.release(), url_launcher_.release()); | |
34 | |
35 return window_ != NULL; | |
36 } | |
37 | |
38 void ReadyPromptContent::SetDimensions(const RECT& dimensions) { | |
39 if (window_ != NULL && window_->IsWindow()) { | |
40 window_->SetWindowPos(HWND_TOP, &dimensions, | |
41 ::IsRectEmpty(&dimensions) ? SWP_HIDEWINDOW : | |
42 SWP_SHOWWINDOW); | |
43 } | |
44 } | |
45 | |
46 bool GetDialogTemplateDimensions(ReadyPromptWindow* window, RECT* dimensions) { | |
47 HRSRC resource = ::FindResource(_AtlBaseModule.GetResourceInstance(), | |
48 MAKEINTRESOURCE(ReadyPromptWindow::IDD), | |
49 RT_DIALOG); | |
50 | |
51 HGLOBAL handle = NULL; | |
52 DLGTEMPLATE* dlgtemplate = NULL; | |
53 _DialogSplitHelper::DLGTEMPLATEEX* dlgtemplateex = NULL; | |
54 | |
55 if (resource == NULL) { | |
56 DPLOG(ERROR) << "Failed to find resource for ReadyPromptWindow::IDD"; | |
57 return false; | |
58 } | |
59 | |
60 handle = ::LoadResource(_AtlBaseModule.GetResourceInstance(), resource); | |
61 | |
62 if (handle == NULL) { | |
63 DPLOG(ERROR) << "Failed to load resource for ReadyPromptWindow::IDD"; | |
64 return false; | |
65 } | |
66 | |
67 dlgtemplate = reinterpret_cast<DLGTEMPLATE*>(::LockResource(handle)); | |
68 if (dlgtemplate == NULL) { | |
69 DPLOG(ERROR) << "Failed to lock resource for ReadyPromptWindow::IDD"; | |
70 return false; | |
71 } | |
72 | |
73 if (!_DialogSplitHelper::IsDialogEx(dlgtemplate)) { | |
74 DLOG(ERROR) << "Resource ReadyPromptWindow::IDD is not a DLGTEMPLATEEX"; | |
75 return false; | |
76 } | |
77 | |
78 dlgtemplateex = | |
79 reinterpret_cast<_DialogSplitHelper::DLGTEMPLATEEX*>(dlgtemplate); | |
80 | |
81 RECT dlgdimensions = {0, 0, dlgtemplateex->cx, dlgtemplateex->cy}; | |
82 if (!window->MapDialogRect(&dlgdimensions)) { | |
83 DPLOG(ERROR) << "Failure in MapDialogRect"; | |
84 return false; | |
85 } | |
86 | |
87 *dimensions = dlgdimensions; | |
88 return true; | |
89 } | |
90 | |
91 size_t ReadyPromptContent::GetDesiredSize(size_t width, size_t height) { | |
92 DCHECK(window_ != NULL && window_->IsWindow()); | |
93 | |
94 if (window_ == NULL || !window_->IsWindow()) { | |
95 return 0; | |
96 } | |
97 RECT dialog_dimensions = {0, 0, 0, 0}; | |
98 | |
99 if (GetDialogTemplateDimensions(window_.get(), &dialog_dimensions)) | |
100 return width == 0 ? dialog_dimensions.right : dialog_dimensions.bottom; | |
101 else | |
102 return width == 0 ? 0 : 39; | |
103 } | |
OLD | NEW |