Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome_frame/turndown_prompt/turndown_prompt_window.h" | 5 #include "chrome_frame/turndown_prompt/turndown_prompt_window.h" |
| 6 | 6 |
| 7 #include <atlctrls.h> | 7 #include <atlctrls.h> |
| 8 #include <commctrl.h> | 8 #include <commctrl.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "chrome_frame/ready_mode/internal/url_launcher.h" | 12 #include "chrome_frame/ready_mode/internal/url_launcher.h" |
| 13 #include "chrome_frame/simple_resource_loader.h" | 13 #include "chrome_frame/simple_resource_loader.h" |
| 14 #include "chrome_frame/utils.h" | 14 #include "chrome_frame/utils.h" |
| 15 #include "grit/chrome_frame_dialogs.h" | 15 #include "grit/chrome_frame_dialogs.h" |
| 16 #include "grit/chrome_frame_resources.h" | |
| 16 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
| 17 | 18 |
| 18 // atlctrlx.h requires 'min' and 'max' macros, the definition of which conflicts | 19 // atlctrlx.h requires 'min' and 'max' macros, the definition of which conflicts |
| 19 // with STL headers. Hence we include them out of the order defined by style | 20 // with STL headers. Hence we include them out of the order defined by style |
| 20 // guidelines. As a result you may not refer to std::min or std::max in this | 21 // guidelines. As a result you may not refer to std::min or std::max in this |
| 21 // file. | 22 // file. |
| 22 #include <minmax.h> // NOLINT | 23 #include <minmax.h> // NOLINT |
| 23 #include <atlctrlx.h> // NOLINT | 24 #include <atlctrlx.h> // NOLINT |
| 24 | 25 |
| 26 namespace { | |
| 27 const uint32 kBitmapImageSize = 18; | |
| 28 } // namespace | |
| 29 | |
| 30 // WTL's CBitmapButton's drawing code is horribly broken when using transparent | |
| 31 // images (specifically, it doesn't clear the background between redraws). | |
| 32 // Fix it here. | |
| 33 class CFBitmapButton: public CBitmapButtonImpl<CFBitmapButton> | |
| 34 { | |
| 35 public: | |
| 36 DECLARE_WND_SUPERCLASS(_T("WTL_BitmapButton"), GetWndClassName()) | |
| 37 | |
| 38 CFBitmapButton() : | |
|
grt (UTC plus 2)
2013/07/22 16:07:27
CFBitmapButton()
: CBitmapButtonImpl<CFBitma
robertshield
2013/07/22 19:58:57
Done.
| |
| 39 CBitmapButtonImpl<CFBitmapButton>(BMPBTN_AUTOSIZE | BMPBTN_HOVER, NULL) {} | |
| 40 | |
| 41 // "Overridden" from CBitmapButtonImpl via template hackery. See | |
| 42 // CBitmapButtonImpl::OnPaint() in atlctrlx.h for details. | |
| 43 void DoPaint(CDCHandle dc) { | |
| 44 RECT rc; | |
| 45 GetClientRect(&rc); | |
| 46 dc.FillRect(&rc, (HBRUSH)(COLOR_BTNFACE+1)); | |
|
grt (UTC plus 2)
2013/07/22 16:07:27
reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1)
robertshield
2013/07/22 19:58:57
Done.
| |
| 47 | |
| 48 // Call original implementation. | |
| 49 CBitmapButtonImpl<CFBitmapButton>::DoPaint(dc); | |
| 50 } | |
| 51 }; | |
| 52 | |
| 53 // static | |
| 25 base::WeakPtr<TurndownPromptWindow> TurndownPromptWindow::CreateInstance( | 54 base::WeakPtr<TurndownPromptWindow> TurndownPromptWindow::CreateInstance( |
| 26 InfobarContent::Frame* frame, | 55 InfobarContent::Frame* frame, |
| 27 UrlLauncher* url_launcher, | 56 UrlLauncher* url_launcher, |
| 28 const base::Closure& uninstall_callback) { | 57 const base::Closure& uninstall_callback) { |
| 29 DCHECK(frame != NULL); | 58 DCHECK(frame != NULL); |
| 30 DCHECK(url_launcher != NULL); | 59 DCHECK(url_launcher != NULL); |
| 31 | 60 |
| 32 base::WeakPtr<TurndownPromptWindow> instance( | 61 base::WeakPtr<TurndownPromptWindow> instance( |
| 33 (new TurndownPromptWindow(frame, url_launcher, uninstall_callback)) | 62 (new TurndownPromptWindow(frame, url_launcher, uninstall_callback)) |
| 34 ->weak_ptr_factory_.GetWeakPtr()); | 63 ->weak_ptr_factory_.GetWeakPtr()); |
| 35 | 64 |
| 36 DCHECK(!instance->IsWindow()); | 65 DCHECK(!instance->IsWindow()); |
| 37 | 66 |
| 38 if (instance->Create(frame->GetFrameWindow()) == NULL) { | 67 if (instance->Create(frame->GetFrameWindow()) == NULL) { |
| 39 DPLOG(ERROR) << "Failed to create HWND for TurndownPromptWindow."; | 68 DPLOG(ERROR) << "Failed to create HWND for TurndownPromptWindow."; |
| 40 return base::WeakPtr<TurndownPromptWindow>(); | 69 return base::WeakPtr<TurndownPromptWindow>(); |
| 41 } | 70 } |
| 42 | 71 |
| 43 // Subclass the "Learn more." text to make it behave like a link. Clicks are | 72 // Subclass the "Learn more." text to make it behave like a link. Clicks are |
| 44 // routed to OnLearnMore(). | 73 // routed to OnLearnMore(). |
| 45 CWindow rte = instance->GetDlgItem(IDC_TD_PROMPT_LINK); | 74 CWindow rte = instance->GetDlgItem(IDC_TD_PROMPT_LINK); |
| 46 instance->link_.reset(new CHyperLink()); | 75 instance->link_.reset(new CHyperLink()); |
| 47 instance->link_->SubclassWindow(rte); | 76 instance->link_->SubclassWindow(rte); |
| 48 instance->link_->SetHyperLinkExtendedStyle(HLINK_NOTIFYBUTTON, | 77 instance->link_->SetHyperLinkExtendedStyle(HLINK_NOTIFYBUTTON, |
| 49 HLINK_NOTIFYBUTTON); | 78 HLINK_NOTIFYBUTTON); |
| 50 | 79 |
| 80 SetupBitmapButton(instance); | |
| 81 | |
| 51 // Substitute the proper text given the current IE version. | 82 // Substitute the proper text given the current IE version. |
| 52 CWindow text = instance->GetDlgItem(IDC_TD_PROMPT_MESSAGE); | 83 CWindow text = instance->GetDlgItem(IDC_TD_PROMPT_MESSAGE); |
| 53 string16 prompt_text(GetPromptText()); | 84 string16 prompt_text(GetPromptText()); |
| 54 if (!prompt_text.empty()) | 85 if (!prompt_text.empty()) |
| 55 text.SetWindowText(prompt_text.c_str()); | 86 text.SetWindowText(prompt_text.c_str()); |
| 56 | 87 |
| 57 return instance; | 88 return instance; |
| 58 } | 89 } |
| 59 | 90 |
| 91 // static | |
| 92 void TurndownPromptWindow::SetupBitmapButton( | |
| 93 const base::WeakPtr<TurndownPromptWindow>& instance) { | |
|
grt (UTC plus 2)
2013/07/22 16:07:27
since this function doesn't store |instance| for l
robertshield
2013/07/22 19:58:57
Done.
| |
| 94 CWindow close_window = instance->GetDlgItem(IDDISMISS); | |
| 95 instance->close_button_.reset(new CFBitmapButton()); | |
| 96 | |
| 97 // Set the resource instance to the current dll which contains the bitmap. | |
| 98 HINSTANCE old_res_module = _AtlBaseModule.GetResourceInstance(); | |
| 99 HINSTANCE this_module = _AtlBaseModule.GetModuleInstance(); | |
| 100 _AtlBaseModule.SetResourceInstance(this_module); | |
| 101 | |
| 102 HBITMAP close_bitmap = static_cast<HBITMAP>( | |
| 103 LoadImage(this_module, MAKEINTRESOURCE(IDB_TURNDOWN_PROMPT_CLOSE_BUTTON), | |
| 104 IMAGE_BITMAP, 0, 0, 0)); | |
| 105 | |
| 106 // Restore the module's resource instance. | |
| 107 _AtlBaseModule.SetResourceInstance(old_res_module); | |
| 108 | |
| 109 // Create the image list with the appropriate size and colour mask. | |
| 110 instance->close_button_->m_ImageList.Create(kBitmapImageSize, | |
| 111 kBitmapImageSize, | |
| 112 ILC_COLOR8|ILC_MASK, 4, 0); | |
|
grt (UTC plus 2)
2013/07/22 16:07:27
ILC_COLOR8 | ILC_MASK
robertshield
2013/07/22 19:58:57
Done.
| |
| 113 instance->close_button_->m_ImageList.Add(close_bitmap, RGB(255,0,255)); | |
|
grt (UTC plus 2)
2013/07/22 16:07:27
255, 0, 255
robertshield
2013/07/22 19:58:57
Done.
| |
| 114 instance->close_button_->m_ImageList.SetBkColor(CLR_NONE); | |
| 115 | |
| 116 // Configure the button states and initialize the button. | |
| 117 instance->close_button_->SetImages(0, 1, 2, 3); | |
|
grt (UTC plus 2)
2013/07/22 16:07:27
4, 5, 6, 7, 8
who do we appreciate
robertshield
ro
robertshield
2013/07/22 19:58:57
\o/
| |
| 118 instance->close_button_->SubclassWindow(close_window); | |
| 119 | |
| 120 // The CDialogResize() implementation incorrectly captures the size | |
| 121 // of the bitmap image button. Reset it here to ensure that resizing works | |
| 122 // as desired. | |
| 123 | |
| 124 // Find the resize data. The parameters here must match the resize map in | |
| 125 // turndown_prompt_window.h. | |
| 126 _AtlDlgResizeData resize_params = { IDDISMISS, DLSZ_CENTER_Y | DLSZ_MOVE_X }; | |
| 127 int resize_index = instance->m_arrData.Find(resize_params); | |
| 128 DCHECK(resize_index > -1 && resize_index < instance->m_arrData.GetSize()); | |
| 129 | |
| 130 // Fiddle CDialogResize's internal data to fix up the size for the image | |
| 131 // control. | |
| 132 _AtlDlgResizeData& resize_data = instance->m_arrData[resize_index]; | |
| 133 resize_data.m_rect.right = resize_data.m_rect.left + kBitmapImageSize; | |
| 134 resize_data.m_rect.top = 0; | |
| 135 resize_data.m_rect.bottom = kBitmapImageSize; | |
| 136 } | |
| 137 | |
| 60 TurndownPromptWindow::TurndownPromptWindow( | 138 TurndownPromptWindow::TurndownPromptWindow( |
| 61 InfobarContent::Frame* frame, | 139 InfobarContent::Frame* frame, |
| 62 UrlLauncher* url_launcher, | 140 UrlLauncher* url_launcher, |
| 63 const base::Closure& uninstall_closure) | 141 const base::Closure& uninstall_closure) |
| 64 : frame_(frame), | 142 : frame_(frame), |
| 65 url_launcher_(url_launcher), | 143 url_launcher_(url_launcher), |
| 66 uninstall_closure_(uninstall_closure), | 144 uninstall_closure_(uninstall_closure), |
| 67 weak_ptr_factory_(this) { | 145 weak_ptr_factory_(this) { |
| 68 } | 146 } |
| 69 | 147 |
| 70 TurndownPromptWindow::~TurndownPromptWindow() {} | 148 TurndownPromptWindow::~TurndownPromptWindow() {} |
| 71 | 149 |
| 72 void TurndownPromptWindow::OnFinalMessage(HWND) { | 150 void TurndownPromptWindow::OnFinalMessage(HWND) { |
| 73 delete this; | 151 delete this; |
| 74 } | 152 } |
| 75 | 153 |
| 76 void TurndownPromptWindow::OnDestroy() { | 154 void TurndownPromptWindow::OnDestroy() { |
| 155 close_button_->m_ImageList.Destroy(); | |
| 77 frame_ = NULL; | 156 frame_ = NULL; |
| 78 } | 157 } |
| 79 | 158 |
| 80 BOOL TurndownPromptWindow::OnInitDialog(CWindow wndFocus, LPARAM lInitParam) { | 159 BOOL TurndownPromptWindow::OnInitDialog(CWindow wndFocus, LPARAM lInitParam) { |
| 81 DlgResize_Init(false); // false => 'no gripper' | 160 DlgResize_Init(false); // false => 'no gripper' |
| 82 return TRUE; | 161 return TRUE; |
| 83 } | 162 } |
| 84 | 163 |
| 85 LRESULT TurndownPromptWindow::OnLearnMore(WORD /*wParam*/, | 164 LRESULT TurndownPromptWindow::OnLearnMore(WORD /*wParam*/, |
| 86 LPNMHDR /*lParam*/, | 165 LPNMHDR /*lParam*/, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 109 } | 188 } |
| 110 | 189 |
| 111 // static | 190 // static |
| 112 string16 TurndownPromptWindow::GetPromptText() { | 191 string16 TurndownPromptWindow::GetPromptText() { |
| 113 IEVersion ie_version = GetIEVersion(); | 192 IEVersion ie_version = GetIEVersion(); |
| 114 int message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_IE_NEWER; | 193 int message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_IE_NEWER; |
| 115 if (ie_version == IE_6 || ie_version == IE_7 || ie_version == IE_8) | 194 if (ie_version == IE_6 || ie_version == IE_7 || ie_version == IE_8) |
| 116 message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_IE_OLDER; | 195 message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_IE_OLDER; |
| 117 return SimpleResourceLoader::GetInstance()->Get(message_id); | 196 return SimpleResourceLoader::GetInstance()->Get(message_id); |
| 118 } | 197 } |
| OLD | NEW |