Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fwl/lightwidget/cfwl_widget.h" | 7 #include "xfa/fwl/lightwidget/cfwl_widget.h" |
| 8 | 8 |
| 9 #include "xfa/fde/tto/fde_textout.h" | 9 #include "xfa/fde/tto/fde_textout.h" |
| 10 #include "xfa/fwl/core/cfwl_themetext.h" | 10 #include "xfa/fwl/core/cfwl_themetext.h" |
| 11 #include "xfa/fwl/core/cfwl_widgetmgr.h" | 11 #include "xfa/fwl/core/cfwl_widgetmgr.h" |
| 12 #include "xfa/fwl/core/fwl_noteimp.h" | 12 #include "xfa/fwl/core/fwl_noteimp.h" |
| 13 #include "xfa/fwl/core/fwl_noteimp.h" | 13 #include "xfa/fwl/core/fwl_noteimp.h" |
| 14 #include "xfa/fwl/core/fwl_widgetimp.h" | 14 #include "xfa/fwl/core/fwl_widgetimp.h" |
| 15 #include "xfa/fwl/core/ifwl_app.h" | 15 #include "xfa/fwl/core/ifwl_app.h" |
| 16 #include "xfa/fwl/core/ifwl_themeprovider.h" | 16 #include "xfa/fwl/core/ifwl_themeprovider.h" |
| 17 | 17 |
| 18 #define FWL_WGT_CalcHeight 2048 | 18 #define FWL_WGT_CalcHeight 2048 |
| 19 #define FWL_WGT_CalcWidth 2048 | 19 #define FWL_WGT_CalcWidth 2048 |
| 20 #define FWL_WGT_CalcMultiLineDefWidth 120.0f | 20 #define FWL_WGT_CalcMultiLineDefWidth 120.0f |
| 21 | 21 |
| 22 IFWL_Widget* CFWL_Widget::GetWidget() { | 22 IFWL_Widget* CFWL_Widget::GetWidget() { |
| 23 return m_pIface; | 23 return m_pIface.get(); |
| 24 } | |
| 25 | |
| 26 const IFWL_Widget* CFWL_Widget::GetWidget() const { | |
| 27 return m_pIface.get(); | |
| 24 } | 28 } |
| 25 | 29 |
| 26 FWL_Error CFWL_Widget::GetClassName(CFX_WideString& wsClass) const { | 30 FWL_Error CFWL_Widget::GetClassName(CFX_WideString& wsClass) const { |
| 27 if (!m_pIface) | 31 if (!m_pIface) |
| 28 return FWL_Error::Indefinite; | 32 return FWL_Error::Indefinite; |
| 29 return m_pIface->GetClassName(wsClass); | 33 return m_pIface->GetClassName(wsClass); |
| 30 } | 34 } |
| 31 | 35 |
| 32 FWL_Type CFWL_Widget::GetClassID() const { | 36 FWL_Type CFWL_Widget::GetClassID() const { |
| 33 if (!m_pIface) | 37 if (!m_pIface) |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 | 205 |
| 202 IFWL_WidgetDelegate* CFWL_Widget::SetDelegate(IFWL_WidgetDelegate* pDelegate) { | 206 IFWL_WidgetDelegate* CFWL_Widget::SetDelegate(IFWL_WidgetDelegate* pDelegate) { |
| 203 if (!m_pIface) | 207 if (!m_pIface) |
| 204 return nullptr; | 208 return nullptr; |
| 205 | 209 |
| 206 m_pDelegate = m_pIface->SetDelegate(pDelegate); | 210 m_pDelegate = m_pIface->SetDelegate(pDelegate); |
| 207 return m_pDelegate; | 211 return m_pDelegate; |
| 208 } | 212 } |
| 209 | 213 |
| 210 CFWL_Widget::CFWL_Widget() | 214 CFWL_Widget::CFWL_Widget() |
| 211 : m_pIface(nullptr), m_pDelegate(nullptr), m_pProperties(nullptr) { | 215 : m_pDelegate(nullptr), m_pProperties(new CFWL_WidgetProperties) { |
| 212 m_pProperties = new CFWL_WidgetProperties; | |
| 213 m_pWidgetMgr = CFWL_WidgetMgr::GetInstance(); | 216 m_pWidgetMgr = CFWL_WidgetMgr::GetInstance(); |
|
Lei Zhang
2016/08/05 17:34:18
Put this in the initializer list and make it a con
Wei Li
2016/08/08 23:55:37
Done.
| |
| 214 ASSERT(m_pWidgetMgr); | 217 ASSERT(m_pWidgetMgr); |
| 215 } | 218 } |
| 216 | 219 |
| 217 CFWL_Widget::~CFWL_Widget() { | 220 CFWL_Widget::~CFWL_Widget() { |
| 218 delete m_pProperties; | 221 if (m_pIface) |
| 219 if (m_pIface) { | |
| 220 m_pIface->Finalize(); | 222 m_pIface->Finalize(); |
| 221 delete m_pIface; | |
| 222 } | |
| 223 } | 223 } |
| 224 | 224 |
| 225 FWL_Error CFWL_Widget::Repaint(const CFX_RectF* pRect) { | 225 FWL_Error CFWL_Widget::Repaint(const CFX_RectF* pRect) { |
| 226 if (!m_pIface) | 226 if (!m_pIface) |
| 227 return FWL_Error::Indefinite; | 227 return FWL_Error::Indefinite; |
| 228 | 228 |
| 229 CFX_RectF rect; | 229 CFX_RectF rect; |
| 230 if (pRect) { | 230 if (pRect) { |
| 231 rect = *pRect; | 231 rect = *pRect; |
| 232 } else { | 232 } else { |
| 233 m_pIface->GetWidgetRect(rect); | 233 m_pIface->GetWidgetRect(rect); |
| 234 rect.left = rect.top = 0; | 234 rect.left = rect.top = 0; |
| 235 } | 235 } |
| 236 return m_pWidgetMgr->RepaintWidget(m_pIface, &rect); | 236 return m_pWidgetMgr->RepaintWidget(m_pIface.get(), &rect); |
| 237 } | 237 } |
| 238 | 238 |
| 239 FWL_Error CFWL_Widget::SetFocus(FX_BOOL bFocus) { | 239 FWL_Error CFWL_Widget::SetFocus(FX_BOOL bFocus) { |
| 240 if (!m_pIface) | 240 if (!m_pIface) |
| 241 return FWL_Error::Indefinite; | 241 return FWL_Error::Indefinite; |
| 242 | 242 |
| 243 IFWL_App* pApp = m_pIface->GetOwnerApp(); | 243 IFWL_App* pApp = m_pIface->GetOwnerApp(); |
| 244 if (!pApp) | 244 if (!pApp) |
| 245 return FWL_Error::Indefinite; | 245 return FWL_Error::Indefinite; |
| 246 | 246 |
| 247 CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); | 247 CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); |
| 248 if (!pDriver) | 248 if (!pDriver) |
| 249 return FWL_Error::Indefinite; | 249 return FWL_Error::Indefinite; |
| 250 | 250 |
| 251 if (bFocus) { | 251 if (bFocus) { |
| 252 pDriver->SetFocus(m_pIface); | 252 pDriver->SetFocus(m_pIface.get()); |
| 253 } else { | 253 } else { |
| 254 if (pDriver->GetFocus() == m_pIface) { | 254 if (pDriver->GetFocus() == m_pIface.get()) { |
| 255 pDriver->SetFocus(nullptr); | 255 pDriver->SetFocus(nullptr); |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 return FWL_Error::Succeeded; | 258 return FWL_Error::Succeeded; |
| 259 } | 259 } |
| 260 | 260 |
| 261 FWL_Error CFWL_Widget::SetGrab(FX_BOOL bSet) { | 261 FWL_Error CFWL_Widget::SetGrab(FX_BOOL bSet) { |
| 262 if (!m_pIface) | 262 if (!m_pIface) |
| 263 return FWL_Error::Indefinite; | 263 return FWL_Error::Indefinite; |
| 264 | 264 |
| 265 IFWL_App* pApp = m_pIface->GetOwnerApp(); | 265 IFWL_App* pApp = m_pIface->GetOwnerApp(); |
| 266 if (!pApp) | 266 if (!pApp) |
| 267 return FWL_Error::Indefinite; | 267 return FWL_Error::Indefinite; |
| 268 | 268 |
| 269 CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); | 269 CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); |
| 270 if (!pDriver) | 270 if (!pDriver) |
| 271 return FWL_Error::Indefinite; | 271 return FWL_Error::Indefinite; |
| 272 | 272 |
| 273 pDriver->SetGrab(m_pIface, bSet); | 273 pDriver->SetGrab(m_pIface.get(), bSet); |
| 274 return FWL_Error::Succeeded; | 274 return FWL_Error::Succeeded; |
| 275 } | 275 } |
| 276 | 276 |
| 277 void CFWL_Widget::RegisterEventTarget(CFWL_Widget* pEventSource, | 277 void CFWL_Widget::RegisterEventTarget(CFWL_Widget* pEventSource, |
| 278 uint32_t dwFilter) { | 278 uint32_t dwFilter) { |
| 279 if (!m_pIface) | 279 if (!m_pIface) |
| 280 return; | 280 return; |
| 281 | 281 |
| 282 IFWL_App* pApp = m_pIface->GetOwnerApp(); | 282 IFWL_App* pApp = m_pIface->GetOwnerApp(); |
| 283 if (!pApp) | 283 if (!pApp) |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 313 FX_BOOL bMultiLine, | 313 FX_BOOL bMultiLine, |
| 314 int32_t iLineWidth) { | 314 int32_t iLineWidth) { |
| 315 if (!m_pIface) | 315 if (!m_pIface) |
| 316 return CFX_SizeF(); | 316 return CFX_SizeF(); |
| 317 | 317 |
| 318 IFWL_ThemeProvider* pTheme = m_pIface->GetThemeProvider(); | 318 IFWL_ThemeProvider* pTheme = m_pIface->GetThemeProvider(); |
| 319 if (!pTheme) | 319 if (!pTheme) |
| 320 return CFX_SizeF(); | 320 return CFX_SizeF(); |
| 321 | 321 |
| 322 CFWL_ThemeText calPart; | 322 CFWL_ThemeText calPart; |
| 323 calPart.m_pWidget = m_pIface; | 323 calPart.m_pWidget = m_pIface.get(); |
| 324 calPart.m_wsText = wsText; | 324 calPart.m_wsText = wsText; |
| 325 calPart.m_dwTTOStyles = | 325 calPart.m_dwTTOStyles = |
| 326 bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine; | 326 bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine; |
| 327 calPart.m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; | 327 calPart.m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; |
| 328 CFX_RectF rect; | 328 CFX_RectF rect; |
| 329 FX_FLOAT fWidth = bMultiLine | 329 FX_FLOAT fWidth = bMultiLine |
| 330 ? (iLineWidth > 0 ? (FX_FLOAT)iLineWidth | 330 ? (iLineWidth > 0 ? (FX_FLOAT)iLineWidth |
| 331 : FWL_WGT_CalcMultiLineDefWidth) | 331 : FWL_WGT_CalcMultiLineDefWidth) |
| 332 : FWL_WGT_CalcWidth; | 332 : FWL_WGT_CalcWidth; |
| 333 rect.Set(0, 0, fWidth, FWL_WGT_CalcHeight); | 333 rect.Set(0, 0, fWidth, FWL_WGT_CalcHeight); |
| 334 pTheme->CalcTextRect(&calPart, rect); | 334 pTheme->CalcTextRect(&calPart, rect); |
| 335 return CFX_SizeF(rect.width, rect.height); | 335 return CFX_SizeF(rect.width, rect.height); |
| 336 } | 336 } |
| OLD | NEW |