Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Unified Diff: chrome/browser/ui/views/omnibox/omnibox_view_win.cc

Issue 10545045: Make ScopedGetDC() CHECK fail if GetDC(NULL) returns NULL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/win/scoped_hdc.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/omnibox/omnibox_view_win.cc
===================================================================
--- chrome/browser/ui/views/omnibox/omnibox_view_win.cc (revision 140592)
+++ chrome/browser/ui/views/omnibox/omnibox_view_win.cc (working copy)
@@ -20,6 +20,8 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/win/iat_patch_function.h"
+#include "base/win/scoped_hdc.h"
+#include "base/win/scoped_select_object.h"
#include "base/win/windows_version.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
@@ -492,10 +494,10 @@
reinterpret_cast<LPARAM>(&WordBreakProc));
// Get the metrics for the font.
- HDC hdc = ::GetDC(NULL);
- HGDIOBJ old_font = SelectObject(hdc, font_.GetNativeFont());
+ base::win::ScopedGetDC screen_dc(NULL);
+ base::win::ScopedSelectObject(screen_dc, font_.GetNativeFont());
TEXTMETRIC tm = {0};
- GetTextMetrics(hdc, &tm);
+ GetTextMetrics(screen_dc, &tm);
int cap_height = font_.GetBaseline() - tm.tmInternalLeading;
// The ratio of a font's x-height to its cap height. Sadly, Windows
// doesn't provide a true value for a font's x-height in its text
@@ -512,11 +514,8 @@
// Get the number of twips per pixel, which we need below to offset our text
// by the desired number of pixels.
- const long kTwipsPerPixel = kTwipsPerInch / GetDeviceCaps(hdc, LOGPIXELSY);
- // It's unsafe to delete a DC with a non-stock object selected, so restore the
- // original font.
- SelectObject(hdc, old_font);
- ::ReleaseDC(NULL, hdc);
+ const long kTwipsPerPixel =
+ kTwipsPerInch / GetDeviceCaps(screen_dc, LOGPIXELSY);
// Set the default character style -- adjust to our desired baseline.
CHARFORMAT cf = {0};
« no previous file with comments | « base/win/scoped_hdc.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698