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 <atlbase.h> |
| 8 #include <atlwin.h> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "chrome_frame/ready_mode/internal/ready_mode_state.h" |
| 12 #include "chrome_frame/ready_mode/internal/ready_prompt_window.h" |
| 13 |
| 14 ReadyPromptContent::ReadyPromptContent(ReadyModeState* ready_mode_state) |
| 15 : ready_mode_state_(ready_mode_state) { |
| 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 |
| 30 // The window owns itself upon call to Initialize. |
| 31 ReadyPromptWindow* new_window_ = new ReadyPromptWindow(); |
| 32 window_ = new_window_->Initialize(frame, ready_mode_state_.release()); |
| 33 |
| 34 return window_ != NULL; |
| 35 } |
| 36 |
| 37 void ReadyPromptContent::SetDimensions(const RECT& dimensions) { |
| 38 if (window_ != NULL && window_->IsWindow()) { |
| 39 window_->SetWindowPos(HWND_TOP, &dimensions, |
| 40 ::IsRectEmpty(&dimensions) ? SWP_HIDEWINDOW : |
| 41 SWP_SHOWWINDOW); |
| 42 } |
| 43 } |
| 44 |
| 45 bool GetDialogTemplateDimensions(ReadyPromptWindow* window, RECT* dimensions) { |
| 46 HRSRC resource = ::FindResource(_AtlBaseModule.GetResourceInstance(), |
| 47 MAKEINTRESOURCE(ReadyPromptWindow::IDD), |
| 48 RT_DIALOG); |
| 49 |
| 50 HGLOBAL handle = NULL; |
| 51 DLGTEMPLATE* dlgtemplate = NULL; |
| 52 _DialogSplitHelper::DLGTEMPLATEEX* dlgtemplateex = NULL; |
| 53 |
| 54 if (resource == NULL) { |
| 55 DPLOG(ERROR) << "Failed to find resource for ReadyPromptWindow::IDD"; |
| 56 return false; |
| 57 } |
| 58 |
| 59 handle = ::LoadResource(_AtlBaseModule.GetResourceInstance(), resource); |
| 60 |
| 61 if (handle == NULL) { |
| 62 DPLOG(ERROR) << "Failed to load resource for ReadyPromptWindow::IDD"; |
| 63 return false; |
| 64 } |
| 65 |
| 66 dlgtemplate = reinterpret_cast<DLGTEMPLATE*>(::LockResource(handle)); |
| 67 if (dlgtemplate == NULL) { |
| 68 DPLOG(ERROR) << "Failed to lock resource for ReadyPromptWindow::IDD"; |
| 69 return false; |
| 70 } |
| 71 |
| 72 if (!_DialogSplitHelper::IsDialogEx(dlgtemplate)) { |
| 73 DLOG(ERROR) << "Resource ReadyPromptWindow::IDD is not a DLGTEMPLATEEX"; |
| 74 return false; |
| 75 } |
| 76 |
| 77 dlgtemplateex = |
| 78 reinterpret_cast<_DialogSplitHelper::DLGTEMPLATEEX*>(dlgtemplate); |
| 79 |
| 80 RECT dlgdimensions = {0, 0, dlgtemplateex->cx, dlgtemplateex->cy}; |
| 81 if (!window->MapDialogRect(&dlgdimensions)) { |
| 82 DPLOG(ERROR) << "Failure in MapDialogRect"; |
| 83 return false; |
| 84 } |
| 85 |
| 86 *dimensions = dlgdimensions; |
| 87 return true; |
| 88 } |
| 89 |
| 90 size_t ReadyPromptContent::GetDesiredSize(size_t width, size_t height) { |
| 91 DCHECK(window_ != NULL && window_->IsWindow()); |
| 92 |
| 93 if (window_ == NULL || !window_->IsWindow()) { |
| 94 return 0; |
| 95 } |
| 96 RECT dialog_dimensions = {0, 0, 0, 0}; |
| 97 |
| 98 if (GetDialogTemplateDimensions(window_.get(), &dialog_dimensions)) |
| 99 return width == 0 ? dialog_dimensions.right : dialog_dimensions.bottom; |
| 100 else |
| 101 return width == 0 ? 0 : 39; |
| 102 } |
OLD | NEW |