I'm not sure what you're doing to get \hat to extend—it doesn't for me—but the following sort of works. I'm not totally happy with the spacing. Note that I used \overbrace instead of \hat since it actually does extend.
\newcommand*\hatfrac[2]{
\genfrac{}{}{0pt}{}{#1}{\mathpalette\makehathelper{{#1}{#2}}}
}
\def\makehathelper#1#2{\makehat#1#2}
\def\makehat#1#2#3{
\begingroup
\setbox0\hbox{$\mathsurround0pt #1#2$}
\setbox2\hbox{$\mathsurround0pt #1#3$}
\ifdim\wd0<\wd2
\overbrace{\box2}
\else
\overbrace{\hbox to\wd0{\hfil\box2\hfil}}
\fi
\endgroup
}
The braces don't seem to line up in the two cases. If you make the vinculum (the fraction bar) larger than 0pt, you get a line, of course, but then the braces line up. Try
\[
\hatfrac{abcdefghijkl}{x}
\hatfrac{x}{abcdefghijkl}
\hatfrac{x}{y}
\]
to see what I mean.
Update
I'm leaving my old solution because I suspect that with some modifications, someone can make it work. Here's my current solution.
\newcommand*\hatfrac[2]{
\mathchoice{\makehat\textstyle{#1}{#2}}
{\makehat\scriptstyle{#1}{#2}}
{\makehat\scriptscriptstyle{#1}{#2}}
{\makehat\scriptscriptstyle{#1}{#2}}
}
\def\makehat#1#2#3{
\mathinner{
\hskip\nulldelimiterspace
\setbox0\hbox{\strut$\mathsurround0pt#1#2$}
\setbox2\hbox{\strut\cramped[#1]{#3}}
\dimen0 \wd\ifdim\wd0<\wd2 2\else0\fi
\setbox4\hbox{$\mathsurround0pt\overbrace{\hbox to\dimen0{\hfil}}$}
\dimen0 \wd4
\dimen2 \ht2
\advance\dimen2 \dp2
\advance\dimen2 \ht4
\setbox6\vbox{\hbox to\dimen0{\hfil\unhbox0\hfil}
\nointerlineskip
\box4
\nointerlineskip
\hbox to\dimen0{\hfil\unhbox2\hfil}}
\lower.5\dimen2\box6
\hskip\nulldelimiterspace
}
}
It has one problem, which I hope is minor enough that you can use it. The first is that the numerator and denominator are typeset with a \strut for spacing. What should happen instead is the numerator (resp. denominator) should be moved up (resp. down) some amount dependent on the font and its height+depth. In principle, this is doable, but I'd need to spend a lot more time reading Appendix G of the TeXbook.
EDIT: There was an additional problem regarding cramped math styles that has been resolved thanks to this answer. You need the mathtools package for the \cramped macro. Actually, a similar issue exists with the numerator. The denominator should always be cramped, so using \cramped we can solve it. The numerator should be cramped only when the entire fraction is cramped. I don't know how to test if the current style is cramped or not.