0

* Rename ScopedHDC to ScopedCreateDC

* Use ScopedSelectObject for changed files
BUG=99139
TEST=no user visible change

Review URL: http://codereview.chromium.org/8139022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104441 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
yosin@chromium.org
2011-10-07 05:56:32 +00:00
parent 9e2a313764
commit 83deae2710
7 changed files with 54 additions and 50 deletions

@ -35,19 +35,18 @@ class ScopedGetDC {
private:
HWND hwnd_;
HDC hdc_;
DISALLOW_COPY_AND_ASSIGN(ScopedGetDC);
};
// Like ScopedHandle but for HDC. Only use this on HDCs returned from
// CreateCompatibleDC.
// TODO(yosin) To eliminate confusion with ScopedGetDC, we should rename
// ScopedHDC to ScopedCreateDC.
class ScopedHDC {
// CreateCompatibleDC, CreateDC and CreateIC.
class ScopedCreateDC {
public:
ScopedHDC() : hdc_(NULL) { }
explicit ScopedHDC(HDC h) : hdc_(h) { }
ScopedCreateDC() : hdc_(NULL) { }
explicit ScopedCreateDC(HDC h) : hdc_(h) { }
~ScopedHDC() {
~ScopedCreateDC() {
Close();
}
@ -73,7 +72,8 @@ class ScopedHDC {
}
HDC hdc_;
DISALLOW_COPY_AND_ASSIGN(ScopedHDC);
DISALLOW_COPY_AND_ASSIGN(ScopedCreateDC);
};
} // namespace win

@ -224,7 +224,7 @@ class SendThumbnailTask : public Task {
// Create a DIB, copy the resized image, and send the DIB to Windows.
// We can delete this DIB after sending it to Windows since Windows creates
// a copy of the DIB and use it.
base::win::ScopedHDC hdc(CreateCompatibleDC(NULL));
base::win::ScopedCreateDC hdc(CreateCompatibleDC(NULL));
if (!hdc.Get()) {
LOG(ERROR) << "cannot create a memory DC: " << GetLastError();
return;
@ -339,7 +339,7 @@ class SendLivePreviewTask : public Task {
// tab image into the DIB, and send it to Windows.
// We don't need to paste this tab image onto the frame image since Windows
// automatically pastes it for us.
base::win::ScopedHDC hdc(CreateCompatibleDC(NULL));
base::win::ScopedCreateDC hdc(CreateCompatibleDC(NULL));
if (!hdc.Get()) {
LOG(ERROR) << "cannot create a memory DC: " << GetLastError();
return;

@ -6,6 +6,7 @@
#include "base/win/scoped_gdi_object.h"
#include "base/win/scoped_hdc.h"
#include "base/win/scoped_select_object.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/gdi_util.h"
#include "ui/gfx/rect.h"
@ -17,7 +18,7 @@ gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle,
std::vector<unsigned char>* png_representation) {
// Create a memory DC that's compatible with the window.
HDC window_hdc = GetWindowDC(window_handle);
base::win::ScopedHDC mem_hdc(CreateCompatibleDC(window_hdc));
base::win::ScopedCreateDC mem_hdc(CreateCompatibleDC(window_hdc));
// Create a DIB that's the same size as the window.
RECT content_rect = {0, 0, 0, 0};
@ -35,7 +36,7 @@ gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle,
reinterpret_cast<void **>(&bit_ptr),
NULL, 0));
SelectObject(mem_hdc, bitmap);
base::win::ScopedSelectObject select_bitmap(mem_hdc, bitmap);
// Clear the bitmap to white (so that rounded corners on windows
// show up on a white background, and strangely-shaped windows
// look reasonable). Not capturing an alpha mask saves a

@ -258,7 +258,7 @@ Metafile* PrintWebViewHelper::RenderPage(
// Page used alpha blend, but printer doesn't support it. Rewrite the
// metafile and flatten out the transparency.
base::win::ScopedGetDC screen_dc(NULL);
base::win::ScopedHDC bitmap_dc(CreateCompatibleDC(screen_dc));
base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(screen_dc));
if (!bitmap_dc)
NOTREACHED() << "Bitmap DC creation failed";
SetGraphicsMode(bitmap_dc, GM_ADVANCED);

@ -132,6 +132,7 @@ class PrintSystemWatcherWin : public base::win::ObjectWatcher::Delegate {
class Delegate {
public:
virtual ~Delegate() {}
virtual void OnPrinterAdded() = 0;
virtual void OnPrinterDeleted() = 0;
virtual void OnPrinterChanged() = 0;
@ -364,6 +365,7 @@ class PrintSystemWin : public PrintSystem {
print_data_mime_type, printer_name, job_title,
delegate);
}
private:
// We use a Core class because we want a separate RefCountedThreadSafe
// implementation for ServiceUtilityProcessHost::Client.
@ -633,7 +635,7 @@ class PrintSystemWin : public PrintSystem {
PlatformJobId job_id_;
PrintSystem::JobSpooler::Delegate* delegate_;
int saved_dc_;
base::win::ScopedHDC printer_dc_;
base::win::ScopedCreateDC printer_dc_;
FilePath print_data_file_path_;
base::win::ScopedHandle job_progress_event_;
base::win::ObjectWatcher job_progress_watcher_;
@ -681,6 +683,7 @@ class PrintSystemWin : public PrintSystem {
callback_.reset();
Release();
}
private:
// Called on the service process IO thread.
void GetPrinterCapsAndDefaultsImpl(

@ -8,6 +8,8 @@
#include <wingdi.h>
#include <winspool.h>
#include <string>
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/file_util.h"
@ -124,7 +126,7 @@ TEST_F(EmfPrintingTest, Enumerate) {
// Disabled if no "UnitTest printer" exists.
TEST_F(EmfPrintingTest, PageBreak) {
base::win::ScopedHDC dc(
base::win::ScopedCreateDC dc(
CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL));
if (!dc.Get())
return;

@ -14,6 +14,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/win/scoped_gdi_object.h"
#include "base/win/scoped_hdc.h"
#include "base/win/scoped_select_object.h"
#include "base/win/windows_version.h"
#include "skia/ext/platform_canvas.h"
#include "skia/ext/skia_utils_win.h"
@ -110,7 +111,7 @@ NativeThemeWin::~NativeThemeWin() {
if (theme_dll_) {
// todo (cpu): fix this soon. Making a call to CloseHandles() here breaks
// certain tests and the reliability bots.
//CloseHandles();
// CloseHandles();
FreeLibrary(theme_dll_);
}
}
@ -337,7 +338,7 @@ HRESULT NativeThemeWin::PaintScrollbarArrow(
// specific arrow itself. We don't want to show it "hot" mode, but only
// in "hover" mode.
if (state == kHovered && extra.is_hovering) {
switch(part) {
switch (part) {
case kScrollbarDownArrow:
state_id = ABS_DOWNHOVER;
break;
@ -360,7 +361,7 @@ HRESULT NativeThemeWin::PaintScrollbarArrow(
}
int classic_state = DFCS_SCROLLDOWN;
switch(part) {
switch (part) {
case kScrollbarDownArrow:
classic_state = DFCS_SCROLLDOWN;
break;
@ -377,7 +378,7 @@ HRESULT NativeThemeWin::PaintScrollbarArrow(
NOTREACHED() << "Invalid part: " << part;
break;
}
switch(state) {
switch (state) {
case kDisabled:
classic_state |= DFCS_INACTIVE;
break;
@ -409,7 +410,7 @@ HRESULT NativeThemeWin::PaintScrollbarTrack(
int part_id;
int state_id;
switch(part) {
switch (part) {
case gfx::NativeTheme::kScrollbarHorizontalTrack:
part_id = extra.is_upper ? SBP_UPPERTRACKHORZ : SBP_LOWERTRACKHORZ;
break;
@ -421,7 +422,7 @@ HRESULT NativeThemeWin::PaintScrollbarTrack(
break;
}
switch(state) {
switch (state) {
case kDisabled:
state_id = SCRBS_DISABLED;
break;
@ -471,7 +472,7 @@ HRESULT NativeThemeWin::PaintScrollbarThumb(
int part_id;
int state_id;
switch(part) {
switch (part) {
case gfx::NativeTheme::kScrollbarHorizontalThumb:
part_id = SBP_THUMBBTNHORZ;
break;
@ -489,7 +490,7 @@ HRESULT NativeThemeWin::PaintScrollbarThumb(
break;
}
switch(state) {
switch (state) {
case kDisabled:
state_id = SCRBS_DISABLED;
break;
@ -523,7 +524,7 @@ HRESULT NativeThemeWin::PaintPushButton(HDC hdc,
const gfx::Rect& rect,
const ButtonExtraParams& extra) const {
int state_id;
switch(state) {
switch (state) {
case kDisabled:
state_id = PBS_DISABLED;
break;
@ -551,7 +552,7 @@ HRESULT NativeThemeWin::PaintRadioButton(HDC hdc,
const gfx::Rect& rect,
const ButtonExtraParams& extra) const {
int state_id;
switch(state) {
switch (state) {
case kDisabled:
state_id = extra.checked ? RBS_CHECKEDDISABLED : RBS_UNCHECKEDDISABLED;
break;
@ -579,7 +580,7 @@ HRESULT NativeThemeWin::PaintCheckbox(HDC hdc,
const gfx::Rect& rect,
const ButtonExtraParams& extra) const {
int state_id;
switch(state) {
switch (state) {
case kDisabled:
state_id = extra.checked ? CBS_CHECKEDDISABLED :
extra.indeterminate ? CBS_MIXEDDISABLED :
@ -621,7 +622,7 @@ HRESULT NativeThemeWin::PaintButton(HDC hdc,
// Adjust classic_state based on part, state, and extras.
int classic_state = extra.classic_state;
switch(part_id) {
switch (part_id) {
case BP_CHECKBOX:
classic_state |= DFCS_BUTTONCHECK;
break;
@ -636,7 +637,7 @@ HRESULT NativeThemeWin::PaintButton(HDC hdc,
break;
}
switch(state) {
switch (state) {
case kDisabled:
classic_state |= DFCS_INACTIVE;
break;
@ -707,10 +708,10 @@ HRESULT NativeThemeWin::PaintMenuArrow(HDC hdc,
// are needed for RTL locales on Vista. So use a memory DC and mirror
// the region with GDI's StretchBlt.
Rect r(rect);
base::win::ScopedHDC mem_dc(CreateCompatibleDC(hdc));
base::win::ScopedCreateDC mem_dc(CreateCompatibleDC(hdc));
base::win::ScopedBitmap mem_bitmap(CreateCompatibleBitmap(hdc, r.width(),
r.height()));
HGDIOBJ old_bitmap = SelectObject(mem_dc, mem_bitmap);
base::win::ScopedSelectObject select_bitmap(mem_dc, mem_bitmap);
// Copy and horizontally mirror the background from hdc into mem_dc. Use
// a negative-width source rect, starting at the rightmost pixel.
StretchBlt(mem_dc, 0, 0, r.width(), r.height(),
@ -722,7 +723,6 @@ HRESULT NativeThemeWin::PaintMenuArrow(HDC hdc,
// Copy and mirror the result back into mem_dc.
StretchBlt(hdc, r.x(), r.y(), r.width(), r.height(),
mem_dc, r.width()-1, 0, -r.width(), r.height(), SRCCOPY);
SelectObject(mem_dc, old_bitmap);
return result;
}
}
@ -808,7 +808,7 @@ HRESULT NativeThemeWin::PaintMenuItemBackground(
HANDLE handle = GetThemeHandle(MENU);
RECT rect_win = rect.ToRECT();
int state_id;
switch(state) {
switch (state) {
case kNormal:
state_id = MPI_NORMAL;
break;
@ -838,7 +838,7 @@ HRESULT NativeThemeWin::PaintMenuList(HDC hdc,
HANDLE handle = GetThemeHandle(MENULIST);
RECT rect_win = rect.ToRECT();
int state_id;
switch(state) {
switch (state) {
case kNormal:
state_id = CBXS_NORMAL;
break;
@ -897,7 +897,7 @@ HRESULT NativeThemeWin::PaintSpinButton(
RECT rect_win = rect.ToRECT();
int part_id = extra.spin_up ? SPNP_UP : SPNP_DOWN;
int state_id;
switch(state) {
switch (state) {
case kDisabled:
state_id = extra.spin_up ? UPS_DISABLED : DNS_DISABLED;
break;
@ -962,7 +962,7 @@ HRESULT NativeThemeWin::PaintTrackbar(
part_id = part == kTrackbarTrack ? TKP_TRACKVERT : TKP_THUMBVERT;
int state_id = 0;
switch(state) {
switch (state) {
case kDisabled:
state_id = TUS_DISABLED;
break;
@ -1189,7 +1189,7 @@ HRESULT NativeThemeWin::PaintTextField(
const TextFieldExtraParams& extra) const {
int part_id = EP_EDITTEXT;
int state_id = ETS_NORMAL;
switch(state) {
switch (state) {
case kNormal:
if (extra.is_read_only) {
state_id = ETS_READONLY;
@ -1244,7 +1244,7 @@ HRESULT NativeThemeWin::PaintTextField(HDC hdc,
static DTBGOPTS omit_border_options = {
sizeof(DTBGOPTS),
DTBG_OMITBORDER,
{0,0,0,0}
{ 0, 0, 0, 0 }
};
DTBGOPTS* draw_opts = draw_edges ? NULL : &omit_border_options;
hr = draw_theme_ex_(handle, hdc, part_id, state_id, rect, draw_opts);
@ -1365,8 +1365,8 @@ HRESULT NativeThemeWin::PaintFrameControl(HDC hdc,
if (mask_bitmap == NULL)
return E_OUTOFMEMORY;
base::win::ScopedHDC bitmap_dc(CreateCompatibleDC(NULL));
HGDIOBJ org_bitmap = SelectObject(bitmap_dc, mask_bitmap);
base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(NULL));
base::win::ScopedSelectObject select_bitmap(bitmap_dc, mask_bitmap);
RECT local_rect = { 0, 0, width, height };
DrawFrameControl(bitmap_dc, &local_rect, type, state);
@ -1401,8 +1401,6 @@ HRESULT NativeThemeWin::PaintFrameControl(HDC hdc,
SetBkColor(hdc, old_bg_color);
SetTextColor(hdc, old_text_color);
SelectObject(bitmap_dc, org_bitmap);
return S_OK;
}
@ -1481,7 +1479,7 @@ HANDLE NativeThemeWin::GetThemeHandle(ThemeName theme_name) const {
// static
NativeThemeWin::ThemeName NativeThemeWin::GetThemeName(Part part) {
ThemeName name;
switch(part) {
switch (part) {
case kCheckbox:
case kRadio:
case kPushButton:
@ -1532,7 +1530,7 @@ int NativeThemeWin::GetWindowsPart(Part part,
State state,
const ExtraParams& extra) {
int part_id;
switch(part) {
switch (part) {
case kCheckbox:
part_id = BP_CHECKBOX;
break;
@ -1568,9 +1566,9 @@ int NativeThemeWin::GetWindowsState(Part part,
State state,
const ExtraParams& extra) {
int state_id;
switch(part) {
switch (part) {
case kCheckbox:
switch(state) {
switch (state) {
case kNormal:
state_id = CBS_UNCHECKEDNORMAL;
break;
@ -1589,7 +1587,7 @@ int NativeThemeWin::GetWindowsState(Part part,
}
break;
case kMenuCheck:
switch(state) {
switch (state) {
case kNormal:
case kHovered:
case kPressed:
@ -1608,7 +1606,7 @@ int NativeThemeWin::GetWindowsState(Part part,
case kMenuPopupArrow:
case kMenuPopupGutter:
case kMenuPopupSeparator:
switch(state) {
switch (state) {
case kNormal:
state_id = MBI_NORMAL;
break;
@ -1627,7 +1625,7 @@ int NativeThemeWin::GetWindowsState(Part part,
}
break;
case kPushButton:
switch(state) {
switch (state) {
case kNormal:
state_id = PBS_NORMAL;
break;
@ -1646,7 +1644,7 @@ int NativeThemeWin::GetWindowsState(Part part,
}
break;
case kRadio:
switch(state) {
switch (state) {
case kNormal:
state_id = RBS_UNCHECKEDNORMAL;
break;
@ -1665,7 +1663,7 @@ int NativeThemeWin::GetWindowsState(Part part,
}
break;
case kWindowResizeGripper:
switch(state) {
switch (state) {
case kNormal:
case kHovered:
case kPressed: