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() | |
39 : CBitmapButtonImpl<CFBitmapButton>(BMPBTN_AUTOSIZE | BMPBTN_HOVER, | |
40 NULL) {} | |
41 | |
42 // "Overridden" from CBitmapButtonImpl via template hackery. See | |
43 // CBitmapButtonImpl::OnPaint() in atlctrlx.h for details. | |
44 void DoPaint(CDCHandle dc) { | |
45 RECT rc; | |
cpu_(ooo_6.6-7.5)
2013/07/24 02:05:09
lets rc = {0} or check error on the Get. I vote fo
robertshield
2013/07/24 14:02:54
Done.
| |
46 GetClientRect(&rc); | |
47 dc.FillRect(&rc, reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1)); | |
48 | |
49 // Call original implementation. | |
50 CBitmapButtonImpl<CFBitmapButton>::DoPaint(dc); | |
51 } | |
52 }; | |
53 | |
54 // static | |
25 base::WeakPtr<TurndownPromptWindow> TurndownPromptWindow::CreateInstance( | 55 base::WeakPtr<TurndownPromptWindow> TurndownPromptWindow::CreateInstance( |
26 InfobarContent::Frame* frame, | 56 InfobarContent::Frame* frame, |
27 UrlLauncher* url_launcher, | 57 UrlLauncher* url_launcher, |
28 const base::Closure& uninstall_callback) { | 58 const base::Closure& uninstall_callback) { |
29 DCHECK(frame != NULL); | 59 DCHECK(frame != NULL); |
30 DCHECK(url_launcher != NULL); | 60 DCHECK(url_launcher != NULL); |
31 | 61 |
32 base::WeakPtr<TurndownPromptWindow> instance( | 62 base::WeakPtr<TurndownPromptWindow> instance( |
33 (new TurndownPromptWindow(frame, url_launcher, uninstall_callback)) | 63 (new TurndownPromptWindow(frame, url_launcher, uninstall_callback)) |
34 ->weak_ptr_factory_.GetWeakPtr()); | 64 ->weak_ptr_factory_.GetWeakPtr()); |
35 | 65 |
36 DCHECK(!instance->IsWindow()); | 66 DCHECK(!instance->IsWindow()); |
37 | 67 |
38 if (instance->Create(frame->GetFrameWindow()) == NULL) { | 68 if (instance->Create(frame->GetFrameWindow()) == NULL) { |
39 DPLOG(ERROR) << "Failed to create HWND for TurndownPromptWindow."; | 69 DPLOG(ERROR) << "Failed to create HWND for TurndownPromptWindow."; |
40 return base::WeakPtr<TurndownPromptWindow>(); | 70 return base::WeakPtr<TurndownPromptWindow>(); |
41 } | 71 } |
42 | 72 |
43 // Subclass the "Learn more." text to make it behave like a link. Clicks are | 73 // Subclass the "Learn more." text to make it behave like a link. Clicks are |
44 // routed to OnLearnMore(). | 74 // routed to OnLearnMore(). |
45 CWindow rte = instance->GetDlgItem(IDC_TD_PROMPT_LINK); | 75 CWindow rte = instance->GetDlgItem(IDC_TD_PROMPT_LINK); |
46 instance->link_.reset(new CHyperLink()); | 76 instance->link_.reset(new CHyperLink()); |
47 instance->link_->SubclassWindow(rte); | 77 instance->link_->SubclassWindow(rte); |
48 instance->link_->SetHyperLinkExtendedStyle(HLINK_NOTIFYBUTTON, | 78 instance->link_->SetHyperLinkExtendedStyle(HLINK_NOTIFYBUTTON, |
49 HLINK_NOTIFYBUTTON); | 79 HLINK_NOTIFYBUTTON); |
50 | 80 |
81 SetupBitmapButton(instance.get()); | |
82 | |
51 // Substitute the proper text given the current IE version. | 83 // Substitute the proper text given the current IE version. |
52 CWindow text = instance->GetDlgItem(IDC_TD_PROMPT_MESSAGE); | 84 CWindow text = instance->GetDlgItem(IDC_TD_PROMPT_MESSAGE); |
53 string16 prompt_text(GetPromptText()); | 85 string16 prompt_text(GetPromptText()); |
54 if (!prompt_text.empty()) | 86 if (!prompt_text.empty()) |
55 text.SetWindowText(prompt_text.c_str()); | 87 text.SetWindowText(prompt_text.c_str()); |
56 | 88 |
57 return instance; | 89 return instance; |
58 } | 90 } |
59 | 91 |
60 TurndownPromptWindow::TurndownPromptWindow( | 92 TurndownPromptWindow::TurndownPromptWindow( |
61 InfobarContent::Frame* frame, | 93 InfobarContent::Frame* frame, |
62 UrlLauncher* url_launcher, | 94 UrlLauncher* url_launcher, |
63 const base::Closure& uninstall_closure) | 95 const base::Closure& uninstall_closure) |
64 : frame_(frame), | 96 : frame_(frame), |
65 url_launcher_(url_launcher), | 97 url_launcher_(url_launcher), |
66 uninstall_closure_(uninstall_closure), | 98 uninstall_closure_(uninstall_closure), |
67 weak_ptr_factory_(this) { | 99 weak_ptr_factory_(this) { |
68 } | 100 } |
69 | 101 |
70 TurndownPromptWindow::~TurndownPromptWindow() {} | 102 TurndownPromptWindow::~TurndownPromptWindow() {} |
71 | 103 |
104 // static | |
105 void TurndownPromptWindow::SetupBitmapButton(TurndownPromptWindow* instance) { | |
106 DCHECK(instance); | |
107 CWindow close_window = instance->GetDlgItem(IDDISMISS); | |
108 instance->close_button_.reset(new CFBitmapButton()); | |
109 | |
110 // Set the resource instance to the current dll which contains the bitmap. | |
111 HINSTANCE old_res_module = _AtlBaseModule.GetResourceInstance(); | |
112 HINSTANCE this_module = _AtlBaseModule.GetModuleInstance(); | |
113 _AtlBaseModule.SetResourceInstance(this_module); | |
114 | |
115 HBITMAP close_bitmap = static_cast<HBITMAP>( | |
116 LoadImage(this_module, MAKEINTRESOURCE(IDB_TURNDOWN_PROMPT_CLOSE_BUTTON), | |
117 IMAGE_BITMAP, 0, 0, 0)); | |
118 | |
119 // Restore the module's resource instance. | |
120 _AtlBaseModule.SetResourceInstance(old_res_module); | |
121 | |
122 // Create the image list with the appropriate size and colour mask. | |
123 instance->close_button_->m_ImageList.Create(kBitmapImageSize, | |
124 kBitmapImageSize, | |
125 ILC_COLOR8 | ILC_MASK, 4, 0); | |
126 instance->close_button_->m_ImageList.Add(close_bitmap, RGB(255, 0, 255)); | |
cpu_(ooo_6.6-7.5)
2013/07/24 02:05:09
does the imagelist own the close_bitmap? I forgot
robertshield
2013/07/24 14:02:54
I thought it did, but indeed it doesn't. Thanks fo
| |
127 instance->close_button_->m_ImageList.SetBkColor(CLR_NONE); | |
128 | |
129 // Configure the button states and initialize the button. | |
130 instance->close_button_->SetImages(0, 1, 2, 3); | |
131 instance->close_button_->SubclassWindow(close_window); | |
132 | |
133 // The CDialogResize() implementation incorrectly captures the size | |
134 // of the bitmap image button. Reset it here to ensure that resizing works | |
135 // as desired. | |
136 | |
137 // Find the resize data. The parameters here must match the resize map in | |
138 // turndown_prompt_window.h. | |
139 _AtlDlgResizeData resize_params = { IDDISMISS, DLSZ_CENTER_Y | DLSZ_MOVE_X }; | |
140 int resize_index = instance->m_arrData.Find(resize_params); | |
141 DCHECK(resize_index > -1 && resize_index < instance->m_arrData.GetSize()); | |
142 | |
143 // Fiddle CDialogResize's internal data to fix up the size for the image | |
144 // control. | |
145 _AtlDlgResizeData& resize_data = instance->m_arrData[resize_index]; | |
146 resize_data.m_rect.right = resize_data.m_rect.left + kBitmapImageSize; | |
147 resize_data.m_rect.top = 0; | |
148 resize_data.m_rect.bottom = kBitmapImageSize; | |
149 } | |
150 | |
72 void TurndownPromptWindow::OnFinalMessage(HWND) { | 151 void TurndownPromptWindow::OnFinalMessage(HWND) { |
73 delete this; | 152 delete this; |
74 } | 153 } |
75 | 154 |
76 void TurndownPromptWindow::OnDestroy() { | 155 void TurndownPromptWindow::OnDestroy() { |
156 close_button_->m_ImageList.Destroy(); | |
77 frame_ = NULL; | 157 frame_ = NULL; |
78 } | 158 } |
79 | 159 |
80 BOOL TurndownPromptWindow::OnInitDialog(CWindow wndFocus, LPARAM lInitParam) { | 160 BOOL TurndownPromptWindow::OnInitDialog(CWindow wndFocus, LPARAM lInitParam) { |
81 DlgResize_Init(false); // false => 'no gripper' | 161 DlgResize_Init(false); // false => 'no gripper' |
82 return TRUE; | 162 return TRUE; |
83 } | 163 } |
84 | 164 |
85 LRESULT TurndownPromptWindow::OnLearnMore(WORD /*wParam*/, | 165 LRESULT TurndownPromptWindow::OnLearnMore(WORD /*wParam*/, |
86 LPNMHDR /*lParam*/, | 166 LPNMHDR /*lParam*/, |
(...skipping 22 matching lines...) Expand all Loading... | |
109 } | 189 } |
110 | 190 |
111 // static | 191 // static |
112 string16 TurndownPromptWindow::GetPromptText() { | 192 string16 TurndownPromptWindow::GetPromptText() { |
113 IEVersion ie_version = GetIEVersion(); | 193 IEVersion ie_version = GetIEVersion(); |
114 int message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_IE_NEWER; | 194 int message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_IE_NEWER; |
115 if (ie_version == IE_6 || ie_version == IE_7 || ie_version == IE_8) | 195 if (ie_version == IE_6 || ie_version == IE_7 || ie_version == IE_8) |
116 message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_IE_OLDER; | 196 message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_IE_OLDER; |
117 return SimpleResourceLoader::GetInstance()->Get(message_id); | 197 return SimpleResourceLoader::GetInstance()->Get(message_id); |
118 } | 198 } |
OLD | NEW |